Sum 【HDU
阿新 • • 發佈:2019-01-27
Input
2
Output
2
Hint
1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.
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.
題意:
題目讓我們求的是2的N次冪,但由於N過大,所以需要用到尤拉降冪公式。
#include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <limits> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #define lowbit(x) ( x&(-x) ) using namespace std; typedef long long ll; const ll mod=1e9+7; const ll phi=1e9+6; ll ans=0; char s[100005]; ll mi(ll x, ll y) { ll res=1; while(y) { if(y&1) { res=res*x%mod; } x=x*x%mod; y>>=1; } return res; } int main() { while(scanf("%s",s)!=EOF) { ans=0; int len=(int)strlen(s); for(int i=0; i<len; i++) { ans=(ans*10+s[i]-'0')%phi; } printf("%lld\n",mi(2, (ans+phi-1)%phi)); } return 0; }