zoukankan      html  css  js  c++  java
  • HDU 4704

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

    求(2^n)%mod的方法

    #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
    ",POW(n-1)) ;    
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    添加右键菜单
    闭包和迭代器
    函数的进阶
    函数入门
    文件操作
    深浅拷贝
    小数据池和再谈编码
    字典
    list tuple
    int bool str
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/3965096.html
Copyright © 2011-2022 走看看