예제 #1
0
 int superPow(int a, vector<int>& b) {  
     if(b.empty()) return 1;  
     a = a%1337;  
     int lastBit = b.back();  
     b.pop_back();  
     return (superPow(superPow(a, b), 10) * superPow(a, lastBit))%1337;  
 }
예제 #2
0
  int superPow(int a, vector<int>& b) {
    if(all_same(b, 0)) return 1;
    if(all_same(b, 1)) return a%MOD;

    bool odd_flag = (b.back()&1 != 0);
    reduceby2(b);

    if(odd_flag)
      return (a%MOD * superPow(((a%MOD) * (a%MOD))%MOD, b))%MOD;
    else
      return superPow(((a%MOD) * (a%MOD))%MOD, b)%MOD;
  }
예제 #3
0
 int superPow(int a, vector<int>& b) {
     if(b.empty())
         return 1;
     int m = b.back();
     b.pop_back();
     return powMod(superPow(a, b), 10) * powMod(a, m) % base;
 }
예제 #4
0
파일: superPow.cpp 프로젝트: dalanlan/algo
 int superPow(int a, vector<int>& b) {
     if(b.empty()) {
         return 1;
     }
     int bak = b.back();
     b.pop_back();
     return powMode(superPow(a, b), 10)*powMode(a, bak)%1337;
 }