using System.Collections;
public static void Main()
Console.WriteLine(GetModularOfPOW(7281809, 1527768, 7));
Console.WriteLine(GetModularOf(7281809, 1527768, 1527768, 1527768, 1527768, 1527768, 1527768, 1527768));
static long GetModularOfPOW(int modularBase, int value, uint pow)
return GetModularOf(modularBase, (pow > uint.MinValue) ? Enumerable.Repeat(value, (int)pow).ToArray() : new int[] { value });
static long GetModularOf(int modularBase, params int[] multiples)
var result = new Stack(multiples);
long temp = (Convert.ToInt64(result.Pop()) % Convert.ToInt64(modularBase)) * (Convert.ToInt64(result.Pop()) % Convert.ToInt64(modularBase));
result.Push(temp % modularBase);
return Convert.ToInt64(result.Pop()) % Convert.ToInt64(modularBase);