你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出。
示例 1:
a = 2
b = [3]
结果: 8
示例 2:
a = 2
b = [1,0]
结果: 1024
详见:https://leetcode.com/problems/super-pow/description/

C++:

class Solution {
public:
int superPow(int a, vector<int>& b) {
long long res = 1;
for (int i = 0; i < b.size(); ++i)
{
res = pow(res, 10) * pow(a, b[i]) % 1337;
}
return res;
}
int pow(int x, int n)
{
if (n == 0)
{
return 1;
}
if (n == 1)
{
return x % 1337;
}
return pow(x % 1337, n / 2) * pow(x % 1337, n - n / 2) % 1337;
}
};

参考:https://www.cnblogs.com/grandyang/p/5651982.html

372 Super Pow 超级次方的更多相关文章

  1. [LeetCode] Super Pow 超级次方

    Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large posi ...

  2. leetcode 50. Pow(x, n) 、372. Super Pow

    50. Pow(x, n) 372. Super Pow https://www.cnblogs.com/grandyang/p/5651982.html https://www.jianshu.co ...

  3. 【LeetCode】372. Super Pow 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/super-po ...

  4. LeetCode——372. Super Pow

    题目链接:https://leetcode.com/problems/super-pow/description/ Your task is to calculate ab mod 1337 wher ...

  5. 372. Super Pow

    问题 Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large p ...

  6. Leetcode 372. Super Pow

    使用公式 c = ab  =>  c mod d = [a mod d * b mod d] mod d 所以a^423 mod d = (a^100)^4 * (a ^10)^2 * a^3 ...

  7. 372. Super Pow.txt

    ▶ 指数取模运算 ab % m ▶ 参考维基 https://en.wikipedia.org/wiki/Modular_exponentiation,给了几种计算方法:暴力计算法,保存中间结果法(分 ...

  8. C#版(击败100.00%的提交) - Leetcode 372. 超级次方 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...

  9. Java实现 LeetCode 372 超级次方

    372. 超级次方 你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出. 示例 1: 输入: a = 2, b = [3] 输出: 8 示例 2: ...

随机推荐

  1. linux 用户管理、权限管理

    1.useradd -[ugGdsce]2.passwd 用户名 ================================================ 1.chmod 2.chown 3. ...

  2. hdu - 2066 一个人的旅行(基础最短路)

    http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...

  3. [bzoj1324]Exca王者之剑_最小割

    Exca王者之剑 bzoj-1324 题目大意:题目链接. 注释:略. 想法: 最小割经典模型. 所有格子向源点连权值为格子权值的边. 将棋盘黑白染色后白点反转源汇. 如果两个格子相邻那么黑点向白点连 ...

  4. 2017-10-01-morning

    T1 位运算1(bit) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK拥有一个十进制的数N.它赋予了N一个新的意义:将N每一位都拆开来后再加起来就是N ...

  5. Redis Cluster集群搭建后,客户端的连接研究(Spring/Jedis)(待实践)

    说明:无论是否已经搭建好集群,还是使用什么样的客户端去连接,都是必须把全部IP列表集成进去,然后随机往其中一个IP写. 这样做的好处: 1.随机IP写入之后,Redis Cluster代理层会自动根据 ...

  6. 通过ambari安装hadoop集群

    转载:http://www.cnblogs.com/cenyuhai/p/3295635.html 整个过程走完,问题不大,不过有一个事情要注意的是就算创建数据库的,使用localhost会报错,要使 ...

  7. git锁和钩子以及图形化界面

    1.锁机制 Locking Options 严格锁(strict locking):一个时刻,只有一个人可以占用资源. 乐观锁(optimistic locking):允许多个人同时修改同一文件.乐观 ...

  8. SaltStack学习系列之自定义grains

    Master端 打开存放自定义grains的目录 vim /etc/salt/master file_roots: base: - /srv/salt/ 建立自定义模块 cd /srv/salt mk ...

  9. 013 IPv6

    Router>en Router#config t Enter configuration commands, one per line.  End with CNTL/Z. Router(co ...

  10. man中文手册

    Ubuntu安装man手册 sudo apt-get install manpages-zh CentOS安装man手册 yum install man man中文安装包 yum install ma ...