码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4704

时间:2014-09-10 20:59:21      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   art   

http://acm.hdu.edu.cn/showproblem.php?pid=4704

求(2^n)%mod的方法

bubuko.com,布布扣
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
using namespace std ;

//(2^n)%mod=(2^(n%(mod-1)))%mod

const int mod=1000000007 ;

__int64 POW(int b)
{
    __int64 res=1,a=2 ;
    while(b)
    {
        if(b&1)res=(res*a)%mod ;
        a=(a*a)%mod ;
        b>>=1 ;
    }
    return res ;
}

char s[100005] ;

int main()
{
    while(~scanf("%s",s))
    {
        int len=strlen(s) ;
        __int64 n=0 ;
        for(int i=0 ;i<len ;i++)
            n=(n*10+s[i]-0)%(mod-1) ;
        printf("%I64d\n",POW(n-1)) ;    
    }
    return 0 ;
}
View Code

 

HDU 4704

标签:style   blog   http   color   io   os   ar   for   art   

原文地址:http://www.cnblogs.com/xiaohongmao/p/3965096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!