372. 超级次方
文章目录
- 题意
- 思路
- 代码
题意
题目链接
思路
二进制转化+快速幂
代码
class Solution {
public:int superPow(int a, vector<int>& b) {string tmp;int l = 0;while (l < b.size()) {int x = 0;for (int i = l; i < b.size(); i++){int y = x * 10 + b[i];x = y % 2;b[i] = y / 2;if (b[i] == 0 && i == l)l++;}tmp += (x ? "1" : "0");}//cout << tmp << endl;long ans = 1;long k = a % 1337;for (auto &index : tmp) {if (index == '1')ans = ans * k % 1337;k = (k * k) % 1337;}return ans;}
};