Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created February 18, 2018 07:25
Show Gist options
  • Save unilecs/d62ead0be11d790937a4ebd27f117ee6 to your computer and use it in GitHub Desktop.
Save unilecs/d62ead0be11d790937a4ebd27f117ee6 to your computer and use it in GitHub Desktop.
Задача 72: Возводим в степень
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