Euler's formula descending
b b% +
The major indices can be converted into not more than
index.
Note that this does not require a, p prime.
Note that this does not require a, p prime.
Note that this does not require a, p prime. (The important thing to say three times !!!)
prove not say it, too dishes ...
Fermat's Little Theorem
First, p is a prime number,
letter
. If when 1 gcd (a, p) =
P-1
; if gcd (a, p) = p
P-1
can be seen Fermat's little theorem is a special case of Euler's, i.e. p is a prime number,
Portal: Days passing
Meaning of the questions: Known current of the week, seeking
10000
days of the week.
Analysis:The Fermat's little theorem: 7 is a prime number,
if N is a multiple of 7,
% 7 = 0, the same number of weeks,
multiple if N is not 7,
% =. 7. 1, the number of weeks on the previous day.
Code:
#include<bits/stdc++.h>
using namespace std;
char N[10010];
string str;
int n=0,m;
int main(){
cin>>str;
scanf("%s",N+1);
scanf("%d",&m);
int len=strlen(N+1);
for(int i=1;i<=len;i++){
n=(n*10+N[i]-'0')%7;
}
if(n==0) cout<<str<<endl;
else {
if(str=="Mon") cout<<"Tue";
else if(str=="Tue") cout<<"Wed";
else if(str=="Wed") cout<<"Thu"<<endl;
else if(str=="Thu") cout<<"Fri"<<endl;
else if(str=="Fri") cout<<"Sat"<<endl;
else if(str=="Sat") cout<<"Sun"<<endl;
else if(str=="Sun") cout<<"Mon"<<endl;
}
return 0;
}
Portal: sum
The meaning of problems: the number 1, number 2, number 3, ..., N is equal to the number n of addition different cases (large N is an integer) number of species.
Analysis: using a paddle method, assume N = 3, are: 1 1 1, there are two gaps. No need to add a number to the damper is C (2,0), when two baffles plus a number of C (2,1), when the number of three plus two baffles is C (2,2). Then actually seeking: C (N-1,0) + C (N-1,1) + C (N-1,2) + ... + C (. 1-N, N-. 1) = 2 N-. 1 .
The answer mod 1e9 + 7. Then simulated for N an integer modulo a large 1e9 + 6, and finally -1. Then a power of quick answers.
Code:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int mod=1e9+7;
char s[100010];
int N[100010];
int main(){
while(~scanf("%s",s+1)){
int len=strlen(s+1);
long long sum=0;
for(int i=1;i<=len;++i){
sum=(sum*10+s[i]-'0')%(mod-1);
}
sum--;
long long ans=1,tmp=2;
while(sum){
if(sum&1) ans=(ans*tmp)%mod;
tmp=(tmp*tmp)%mod;
sum/=2;
}
cout<<ans<<endl;
}
return 0;
}
Portal: God and the correct use of the set
The meaning of problems:
Analysis: Consider Euler descending, F (P) = 2 2% Oula (P) + P % P, F (Oula (P)) = 2 2% Oula (Oula (P)) + Oula (P ) % Oula (the p-), we can see that this is a recursive, if the direct recursive time complexity is feasible?
p to Oula (p) = p * (. 1-p / p . 1 ) ... * (. 1-p / p n- ). When p is even, there must be p 1 = 2, will be multiplied by 2; when p is odd, Oula (p) must be an even number, because it contains an odd prime factors of 1- (1 / odd) is generated even factor.
Code:
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int oula(int n){
int rea=n;
for(int i=2;i*i<=n;i++){
if(n%i==0){
rea=rea-rea/i;
do{
n/=i;
}while(n%i==0);
}
}
if(n>1) rea=rea-rea/n;
return rea;
}
int qp(int a,int b,int p){
int ans=1,tmp=a;
while(b){
if(b&1) ans=(1ll*ans*tmp)%p;
tmp=(1ll*tmp*tmp)%p;
b/=2;
}
return ans;
}
map<int,int> mmp;
int f(int p){
if(mmp[p]!=0) return mmp[p];
int ol=oula(p);
if(p==1||p==2){
return 0;
}
int t=qp(2,f(ol)+ol,p);
mmp[p]=t;
return t;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
int p;
scanf("%d",&p);
printf("%d\n",f(p));
}
return 0;
}