Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.

Example1:

a = 2
b = [3] Result: 8

Example2:

a = 2
b = [1,0] Result: 1024

使用公式 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

 class Solution(object):
def superPow(self, a, b):
"""
:type a: int
:type b: List[int]
:rtype: int
"""
ans = 1
mod = 1337
for i in b[::-1]:
ans = ans * a ** i % mod
a = a ** 10 % mod
return ans % mod
												

Leetcode 372. Super Pow的更多相关文章

  1. LeetCode——372. Super Pow

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

  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. 372 Super Pow 超级次方

    你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出.示例 1:a = 2b = [3]结果: 8示例 2:a = 2b = [1,0]结果: 102 ...

  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. 372. Super Pow.txt

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

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

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

  8. [LeetCode] Super Pow 超级次方

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

  9. leetcode Super Pow

    题目描述: superPow(int a, int[] b),b是一个int数组,每个元素都是正的个位数,组合起来表示一个正整数,例如b=[1,2,3]表示123,求解a^b mod 1337. 思路 ...

随机推荐

  1. 01传智_jbpm与OA项目_整体项目架构

    oA项目: 项目结构如下:

  2. ValidateAntiForgeryToken 防止CSRF(跨网站请求伪造)

    用途:防止CSRF(跨网站请求伪造). 用法:在View->Form表单中:<%:Html.AntiForgeryToken()%> 在Controller->Action动作 ...

  3. 学习jQuery的on事件

    开发asp.net mvc程序,多少是离不开jQuery客户程序.今天Insus.NET学习jQuery的一个on事件驱动. 先在网页视图放一个图片铵钮,用户可以使用mouse对这图片时行over,o ...

  4. css3属性书写顺序

    今天写了个小demo想要利用transition 和transform以及transition-delay来实现鼠标移上去的延时动画,结果发现不能实现transition的变化效果.调试后发现只有把 ...

  5. NOI2018准备Day7

    昨天没写,就不补了. 晚上追剧到3点,今天困死...... 上午做了一道水题,然后找一个程序的神奇的错误花了3个小时 下午做了3道递归吧,稍微难一点儿的黄金题就卡了 刚开始学递归时没多做题练练,现在 ...

  6. eclipse: workspace出错导致无法启用的解决

    通常我们会在eclipse中创建多个workspace,比如一个用于学习,一个用于工作... ,因为种种原因,时不时会发现eclipse切换workspace后启动失败,提示让你去看workspace ...

  7. 一款炫酷的幻灯片播放框架介绍(附demo及使用方法)

    废话不多说,先上demo(建议在chrome下打开 F键全屏 esc退出全屏): 我的demo-博客园简介 官网demo 更多demo 今天为大家介绍一款基于css3和JavaScript的幻灯片播放 ...

  8. C#基础之IEnumerable

    1.IEnumerable的作用 在使用Linq查询数据时经常以IEnumerable<T>来作为数据查询返回对象,在使用foreach进行遍历时需要该对象实现IEnumerable接口, ...

  9. 关于mvc5+EF里面的db.Entry(model).State = EntityState.Modified报错问题

    最近在使用mvc5+EF的的时候用到了这句话 db.Entry(model).State = EntityState.Modified 看上去很简单的修改数据,但是一直报错,说是key已经存在,不能修 ...

  10. 通向高可扩展性之路(推特篇) ---- 一个推特用来支撑1亿5千万活跃用户、30万QPS、22MB每秒Firehose、以及5秒内推送信息的架构

    原文链接:http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active ...