hdu 4704 Sum 指數迴圈節
阿新 • • 發佈:2019-01-31
#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<climits> #include<queue> #include<vector> #include<map> #include<sstream> #include<set> #include<stack> #include<cctype> #include<utility> #pragma comment(linker, "/STACK:102400000,102400000") #define PI 3.1415926535897932384626 #define eps 1e-10 #define sqr(x) ((x)*(x)) #define FOR0(i,n) for(int i=0 ;i<(n) ;i++) #define FOR1(i,n) for(int i=1 ;i<=(n) ;i++) #define FORD(i,n) for(int i=(n) ;i>=0 ;i--) #define lson num<<1,le,mid #define rson num<<1|1,mid+1,ri #define MID int mid=(le+ri)>>1 #define zero(x)((x>0? x:-x)<1e-15) #define mk make_pair #define _f first #define _s second using namespace std; //const int INF= ; typedef long long ll; //const ll inf =1000000000000000;//1e15; //ifstream fin("input.txt"); //ofstream fout("output.txt"); //fin.close(); //fout.close(); //freopen("a.in","r",stdin); //freopen("a.out","w",stdout); const int INF =0x3f3f3f3f; //const int maxn= ; //const int maxm= ; char s[100000+20]; const ll mod=1e9+7; ll phi; ll getphi(ll x) { ll ans=x; for(ll i=2;i*i<=x;i++) { if(x%i) continue; ans=ans/i*(i-1); while(x%i==0) { x/=i; } } if(x>1) ans=ans/x*(x-1); return ans; } ll qb(ll base,ll k) { ll ans=1; base%=mod; while(k) { if(k&1) ans=ans*base%mod; base=base*base%mod; k>>=1; } return ans; } int main() { // cout<<getphi(mod)<<endl; phi= getphi(mod); while(~scanf("%s",s)) { ll ret=0; for(int i=0;s[i];i++) { ret=ret*10+s[i]-'0'; ret=ret%phi; } ret=(ret-1+phi)%phi; ret+=phi; printf("%lld\n",qb(2,ret) ); } return 0; }