Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int ModuloPower(int value, int exponent, int modulus)
- {
- int res = 1;
- while (exponent > 0)
- {
- if ((exponent & 1) != 0)
- {
- res = (res * value) % modulus;
- }
- value = (value * value) % modulus;
- exponent >>= 1;
- }
- return res;
- }
- static void PrintCalcModulo()
- {
- int a, x, p;
- Console.Write(" Enter number a: ");
- a = Convert.ToInt32(Console.ReadLine());
- Console.Write(" Enter number x: ");
- x = Convert.ToInt32(Console.ReadLine());
- Console.Write(" Enter number p: ");
- p = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("\n {0}^{1} mod {2} = {3}", a, x, p, ModuloPower(a, x, p));
- }
Advertisement
Add Comment
Please, Sign In to add comment