博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode Super Pow详解
阅读量:4185 次
发布时间:2019-05-26

本文共 1057 字,大约阅读时间需要 3 分钟。

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.

如果对模幂算法不了解可参考

#include 
#include
#include
using namespace std;const int modulus = 1024;int modpow(int base, int exponent, int modulus) { int result = 1; while (exponent > 0) { if (exponent & 1) { // multiply in this bit's contribution while using modulus to keep result small result = (result * base) % modulus; } // move to the next bit of the exponent, square (and mod) the base accordingly exponent >>= 1; base = (base * base) % modulus; } return result;}int superPow(int a, vector
& b){ int n = b.size(); int result = 1; for (int i = n - 1; i >= 0; i--) { result = (result*modpow(a, b[i], modulus)) % modulus; a = modpow(a, 10,modulus); } return result;}int main(){ vector
b = { 1,0 }; //cout << modpow(4, 13, 497) << endl; cout << superPow(2, b);}

转载地址:http://dvdoi.baihongyu.com/

你可能感兴趣的文章
DDR3基本概念8 - 如何理解RTT和VTT
查看>>
DDR3基本概念9 - 8n pre-fetch architecture的含义
查看>>
DDR3基本概念10 - DDR MT/S的理解
查看>>
git命令缩写配置
查看>>
makefile常见问题
查看>>
ncverilog编译时Unrecognized system task or function: $fsdbDumpfile问题的解决方法
查看>>
window10配置环境不起作用
查看>>
在官网下载maven历史版本
查看>>
tomcat之启动类BootStrap
查看>>
tomcat处理请求的流程
查看>>
Spring之lazy-init
查看>>
类的加载机制
查看>>
SpringIoc
查看>>
spring bean 的生命周期
查看>>
常用的排序算法
查看>>
浅谈web授权常用策略随机
查看>>
jenkins自动部署随记
查看>>
Shell命令的随记
查看>>
TCP,HTTP,WEBSOCKET随记
查看>>
关于JVM内存区域的组成以及堆内存的回收原理
查看>>