Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
595 B
5
Indexable
public class Solution {
    public long fastPow(int A, long B, int mod){
        if(B == 0) return 1;
        long pow = fastPow(A, B/2, mod) % mod;
        if(B % 2 == 0){
            return (pow * pow) % mod;
        }
        else{
            return (((pow * pow) % mod) * A) % mod;
        }
    }
    public int solve(int A, int B) {
        
        int mod = (int)(1e9) + 7;
        long fact = 1;
        for(int i = 2; i <= B; i++){
            fact = (fact * i) % (mod - 1);
        }
        long res = fastPow(A, fact, mod);

        return (int)res;
    }
}