题意:求2的n-1次方
解题思路:费马小定理
解题代码:
1 // File Name: 4704.c 2 // Author: darkdream 3 // Created Time: 2013年09月08日 星期日 20时32分42秒 4 5 #include<stdio.h> 6 #include<string.h> 7 #include<stdlib.h> 8 #include<time.h> 9 #include<math.h> 10 #define LL long long 11 #define maxn 100009 12 #define mod 1000000007 13 //freopen("/home/plac/problem/input.txt","r",stdin); 14 //freopen("/home/plac/problem/output.txt","w",stdout); 15 16 17 char str[maxn]; 18 LL a[maxn]; 19 LL POW (LL n ,LL k ) 20 { 21 LL ans = 1; 22 LL p = n; 23 while(k) 24 { 25 if(k &1) 26 ans =(ans * p)%mod ; 27 p = p*p %mod; 28 k >>=1; 29 } 30 return ans; 31 } 32 LL len ; 33 LL chu(LL k){ 34 LL temp = 0; 35 for(int i = len;i >=1 ;i --) 36 { 37 temp = temp*10 + a[i]; 38 if(temp > k ) 39 temp = temp%k; 40 } 41 return temp; 42 } 43 void jian() 44 { 45 for(int i = 1;i <= len ;i ++) 46 { 47 if(a[i] >= 1) 48 { 49 a[i] -= 1; 50 return; 51 } 52 else 53 a[i] = 9; 54 } 55 } 56 int main(){ 57 while(scanf("%s",&str[1]) != EOF) 58 { 59 len = strlen(&str[1]); 60 for(int i = 1; i<= len ;i ++) 61 a[i] = str[len-i+1] - '0'; 62 jian(); 63 LL k = chu(mod-1); 64 printf("%lld ",POW(2,k)); 65 } 66 67 return 0 ; 68 }