leetcode:数学:spuer pow(372)

来源:互联网 发布:北京日报新闻网络热线 编辑:程序博客网 时间:2024/05/17 23:29

https://leetcode.com/problems/super-pow/


http://blog.csdn.net/happyxuma1991/article/details/51867822

class Solution {      const int base = 1337;      int powmod(int a, int k) //a^k mod 1337 where 0 <= k <= 10      {          a %= base;          int result = 1;          for (int i = 0; i < k; ++i)              result = (result * a) % base;          return result;      }  public:      int superPow(int a, vector<int>& b) {          if (b.empty()) return 1;          int last_digit = b.back();          b.pop_back();          return powmod(superPow(a, b), 10) * powmod(a, last_digit) % base;      }  };  
0 0
原创粉丝点击