What is the fastest way to compute large power of 2 modulo a number(计算2模数的大幂的最快方法是什么)
本文介绍了计算2模数的大幂的最快方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于 1 <= N <= 1000000000
,我需要计算 2N mod 1000000007
,它一定非常快!
我目前的做法是:
For 1 <= N <= 1000000000
, I need to compute 2N mod 1000000007
, and it must be really fast!
My current approach is:
但它似乎不够快.有什么想法吗?
but it doesn't seem to be fast enough. Any idea?
推荐答案
这样会更快(C 代码):
This will be faster (code in C):
这篇关于计算2模数的大幂的最快方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!