super-pow
// https://discuss.leetcode.com/topic/50489/c-clean-and-short-solution
class Solution {
int base = ;
int powMod(int a, int b) {
a %= base;
int result = ;
for (int i=; i<b; i++) {
result *= a;
result %= base;
}
return result;
}
public:
int superPow(int a, vector<int>& b) {
if (b.empty()) {
return ;
}
int t = b.back();
b.pop_back();
return (powMod(superPow(a, b), ) * powMod(a, t)) % base;
}
};
super-pow的更多相关文章
- 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 ...
- [LeetCode] Super Pow 超级次方
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large posi ...
- [Swift]LeetCode372. 超级次方 | Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and bis an extremely large posit ...
- 372 Super Pow 超级次方
你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出.示例 1:a = 2b = [3]结果: 8示例 2:a = 2b = [1,0]结果: 102 ...
- LeetCode——372. Super Pow
题目链接:https://leetcode.com/problems/super-pow/description/ Your task is to calculate ab mod 1337 wher ...
- 【LeetCode】372. Super Pow 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/super-po ...
- 372. Super Pow
问题 Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large p ...
- leetcode Super Pow
题目描述: superPow(int a, int[] b),b是一个int数组,每个元素都是正的个位数,组合起来表示一个正整数,例如b=[1,2,3]表示123,求解a^b mod 1337. 思路 ...
- 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 ...
- 372. Super Pow.txt
▶ 指数取模运算 ab % m ▶ 参考维基 https://en.wikipedia.org/wiki/Modular_exponentiation,给了几种计算方法:暴力计算法,保存中间结果法(分 ...
随机推荐
- 安卓手机获取IP地址
public class IpGetUtil { public static String getIPAddress(Context context) { NetworkInfo info = ((C ...
- web到service简单原理例子
这是目前的理解 附上服务端源码 package com.lsw.server; import java.io.*; import java.net.*; import java.util.HashMa ...
- hdu-5023线段树刷题
title: hdu-5023线段树刷题 date: 2018-10-18 13:32:13 tags: acm 刷题 categories: ACM-线段树 概述 这道题和上次做的那道染色问题一样, ...
- JAVAEE——宜立方商城12:购物车实现、订单确认页面展示
1. 学习计划 第十二天: 1.购物车实现 2.订单确认页面展示 2. 购物车的实现 2.1. 功能分析 1.购物车是一个独立的表现层工程. 2.添加购物车不要求登录.可以指定购买商品的数量. 3.展 ...
- Openstack_通用模块_Oslo_vmware 创建 vCenter 虚拟机快照
创建虚拟机快照 vSphere Create Snapshot 文档 Snapshot 是虚拟机磁盘文件(VMDK)在某个点及时的复本.包含了虚拟机所有虚拟磁盘上的数据状态和这个虚拟机的电源状态(on ...
- mysql高性能索引
独立索引: 独立索引是指索引列不能是表达式的一部分,也不能是函数的参数 例1: SELECT actor_id FROM actor WHERE actor_id+1=5 --这种写法,就算在acto ...
- nyoj zb的生日
zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 今天是阴历七月初五,acm队员zb的生日.zb正在和C小加.never在武汉集训.他想给这两位兄弟买点什么庆祝 ...
- [BJOI2010]次小生成树
OJ题号: BZOJ1977.COGS2453 题目大意: 给你一个无向连通图,求严格次小生成树. 思路: 对于一般次小生成树,我们有一个结论:一般次小生成树一定可以通过替换掉最小生成树某一条边得到. ...
- 鸟哥的私房菜:Linux文件与目录管理
1. 目录与路径 1.1 相对路径与绝对路径 绝对路径:路径的写法『一定由根目录 / 写起』,如:/usr/share/doc 这个目录. 相对路径:路径的写法『不是由 / ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...