Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created February 25, 2018 22:42
Show Gist options
  • Save unilecs/be591803618e9cb0b7589a81eaffb844 to your computer and use it in GitHub Desktop.
Save unilecs/be591803618e9cb0b7589a81eaffb844 to your computer and use it in GitHub Desktop.
Задача 74: Несократимая дробь
using System;
public class Program
{
public static int EulerFunc(int n)
{
if (n <= 0)
{
throw new Exception("N should be greater than 0!");
}
int result = n;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
result -= result / i;
}
while (n % i == 0)
{
n /= i;
}
}
if (n > 1)
{
result -= result / n;
}
return result;
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", EulerFunc(11))); // 10
Console.WriteLine(string.Format("Answer = {0}", EulerFunc(12))); // 4
Console.WriteLine(string.Format("Answer = {0}", EulerFunc(17))); // 16
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment