标签:hdu pre 快速 ons case code des pac long
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<string.h> 5 using namespace std; 6 7 #define MOD 1000000007 8 9 long long quick_mod(long long a,long long b,long long m)//快速幂,复杂度log2n 10 { 11 long long ans=1; 12 while(b) 13 { 14 if(b&1) 15 { 16 ans=(ans*a)%m; 17 b--; 18 } 19 b/=2; 20 a=a*a%m; 21 } 22 return ans; 23 } 24 25 int main() 26 { 27 28 char str[100010]; 29 long long sum; 30 int len,i; 31 long long M=MOD-1; 32 while(scanf("%s",str)!=EOF) 33 { 34 len=strlen(str); 35 sum=0; 36 for(i=0;i<len;i++) 37 { 38 sum=sum*10+(str[i]-‘0‘); 39 sum=sum%M;//费马小定理 40 } 41 printf("%lld\n",quick_mod(2,(sum-1),MOD));//快速幂 42 } 43 return 0; 44 }
HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
标签:hdu pre 快速 ons case code des pac long
原文地址:http://www.cnblogs.com/Annetree/p/7097750.html