-
-
Save unilecs/be591803618e9cb0b7589a81eaffb844 to your computer and use it in GitHub Desktop.
Задача 74: Несократимая дробь
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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