using System.Collections.Generic;
public static int ComputePowerFnRecursively(int A, int B, double C){
answer = Program.ComputePowerFnRecursively(A, (B / 2), C) % (long)C;
answer = (answer * answer) % (long)C;
answer = (answer * Program.ComputePowerFnRecursively(A, (B - 1), C) % (long)C) % (long)C;
return (int)((answer + C) % C);
private static int FindFactorialRecursively(int num){
long mod = (long)1e9 + 7;
return (int)(num % (mod - 1) * Program.FindFactorialRecursively(num - 1) % (mod - 1));
public static void Main()
long C = (long)(1e9 + 7);
int factVal = Program.FindFactorialRecursively(B);
int PowerValue = Program.ComputePowerFnRecursively(A, factVal, C);
Console.WriteLine("The Power Value is : " + PowerValue);