Descending algorithm

Euler's formula descending

a a b a ≡a b% Phi ( p ) z (p) + Phi ( p ) z (p) ( m O d p ) (modp) b > φ ( p ) (b>φ(p))

The major indices can be converted into not more than φ ( p ) z (p) 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, a a letter a ( m o d p ) ≡a(modp) . If when 1 gcd (a, p) = a a P-1 1 ( m o d p ) ≡1(modp) ; if gcd (a, p) = p a a P-1 0 ( m o d p ) ≡0(modp)
can be seen Fermat's little theorem is a special case of Euler's, i.e. p is a prime number, φ ( p ) = p 1 φ (p) = p-1.


Portal: Days passing

Meaning of the questions: Known current of the week, seeking N M ( 1 < = N < 10 N^M(1<=N<10 10000 , 6 < = M < 10000 , M 6 ) , 6 <= M <10000, M is an integer multiple of 6) days of the week.
Analysis:The Fermat's little theorem: 7 is a prime number,
if N is a multiple of 7, N M N^M % 7 = 0, the same number of weeks,
multiple if N is not 7, N M N^M % =. 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: Here Insert Picture Description
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;
}

Published 96 original articles · won praise 11 · views 2265

Guess you like

Origin blog.csdn.net/weixin_43769146/article/details/103963447