C ++中的超级战俘
让我们看下面的实现以更好地理解-
#include <bits/stdc++.h> using namespace std; typedef long long int lli; class Solution { public: int powerMod(lli base, lli power){ lli mod = 1337; lli ret = 1; while(power){ if(power & 1) ret = (ret * base) % mod; base = (base * base) % mod; power >>= 1; } return ret; } int superPow(int a, vector<int>& b) { if(b.size() == 0) return 1; int last = b.back(); b.pop_back(); return (powerMod(superPow(a, b), 10) * powerMod(a, last)) % 1337; } }; main(){ Solution ob; vector<int> v = {1,0}; cout << (ob.superPow(2, v)); }
输入值
2 [1,0]
输出结果
1024