hdu 4704 Sum
Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 757 Accepted Submission(s): 363
Problem Description
Sample Input
2
Sample Output
2
Hint
1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases. #include<cstdio> #include<cstring> #include<iostream> using namespace std ; typedef long long LL ; int MM = 1000000006 ; char s[100001] ; LL pow_mod( LL a , int n ) { int mm = MM+1 ; if( n == 0 ) return 1 ; LL ans = pow_mod( a , n/2 ) ; ans = ((ans))*ans%mm; if((n&1)) ans = a*ans%mm ; return ans%mm; } int mod() { int i , n ; LL ans = 0 ; n = strlen(s) ; // 大数取模 for( i = 0 ; i < n ;i++ ) { ans = ( ans*10 + (s[i]-'0'))%MM; } return (int)ans-1 ; } int main() { int ans ; while( scanf("%s" , s ) != EOF ) { // 费马小定理 a^phip % p == 1 ; // 将次公式a^n % p == a^(n%phip+phip)%p ; ans = (int)pow_mod(2,mod()) ; printf("%d\n" , ans ) ; } return 0 ; }