Number theory topics

P1082 congruence equation

I.e. a mold find the inverse element b x
because x unique in the sense die b, the smallest integer that is an inverse element solution

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define R register
#define EN printf("\n")
#define LL long long
inline LL read(){
    LL x=0,y=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+(c^48);c=getchar();}
    return x*y;
}
int gcd(LL a,LL b,LL& x,LL& y){
    if(b){
        int d=gcd(b,a%b,y,x);
        //d=y*b+x*(a%b)
        //d=y*b+x*(a-(a/b)*b)
        //d=y*b+x*a-x*(a/b)*b
        //d=x*a+(y-(a/b)*x)*b
        y-=(a/b)*x;
        return d;
    }
    x=1;y=0;
    //赋值后,上一层的d=0*0+a*1=a
    return a;
}
int main(){
    LL a=read(),b=read(),x,y;
    gcd(a,b,x,y);
    while(x<0) x+=b;
    x%=b;
    printf("%lld",x);
    return 0;
}

Research about the number P1043

The number of from about 1 to logarithmically and n are each numbers
as divisors number and equal to a multiple number and (a divisible relation, can be regarded as a multiple or submultiple relationship relationship, i.e., about one-fold and the number)
so the answer is \ (\ sum_ {i = 1 } ^ n \ lfloor \ frac {n} {i} \ rfloor \)

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#define R register
#define LL long long
inline int read(){
    int x=0,y=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') y=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=x*10+(c^48);
        c=getchar();
    }
    return x*y;
}
int n;
LL ans;
int main(){
    n=read();
    for(R int i=1;i<=n;i++) ans+=n/i;
    printf("%lld",ans);
    return 0;
}

SP2 PRIME1 - Prime Generator

Seeking m, primes between n
due to the determination of the number less than equal to n, so if it is a composite number, there must be a prime factor less \ (\ sqrt {n} \
) so to obtain these prime numbers, then the m to n section in addition to violence by their test sieve

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define R register
#define EN printf("\n")
#define LL long long
inline int read(){
    int x=0,y=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+(c^48);c=getchar();}
    return x*y;
}
const int sqrtn=35000;
int n,m,prime[10006],notpr[35000];
inline void getprime(){
    for(R int i=2;i<=sqrtn;i++){
        if(!notpr[i]) prime[++prime[0]]=i;
        for(R int j=1;j<=prime[0]&&i*prime[j]<=sqrtn;j++){
            notpr[i*prime[j]]=1;
            if(!(i%prime[j])) break;
        }
    }
}
inline void isprime(int num){
    if(num==1) return;
    int sqrt=std::sqrt(num);
    for(R int i=1;i<=prime[0]&&prime[i]<=sqrt;i++)
        if(!(num%prime[i])) return;
    printf("%d\n",num);
}
int main(){
    int t=read();
    getprime();
    while(t--){
        m=read();n=read();
        for(R int i=m;i<=n;i++) isprime(i);
        EN;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/suxxsfe/p/12527055.html