-
-
Save unilecs/d62ead0be11d790937a4ebd27f117ee6 to your computer and use it in GitHub Desktop.
Задача 72: Возводим в степень
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 long PowMod(long a, long b, long m) | |
{ | |
if (b == 0) | |
{ | |
return 1; | |
} | |
if (b % 2 == 0) | |
{ | |
return PowMod((a * a) % m, b / 2, m); | |
} | |
return (a * PowMod(a, b - 1, m)) % m; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
long result = PowMod(595, 703, 991); | |
Console.WriteLine(string.Format("Answer = {0}", result)); // 342 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment