Application gcd

g c d ( a , b ) = m i n ( q a p b ) ( q a ! = p b ) gcd(a,b)=min(qa-pb) (qa!=pb)

Euclid proved extensions available, q a p b = g q*a-p*b=g , if the integer solution g = k g c d ( a , b ) , m i n ( g ) k = 1 g = k * gcd (a, b), when min (g) k = 1

Portal: Infinite Fence
meaning of the questions: judge ( r < b ) p b   ( p 1 ) b (r<b) p*b~(p-1)*b R & lt between is less than a multiple of k

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int r,b,k;
        scanf("%d%d%d",&r,&b,&k);
        int t=__gcd(r,b);
        if((max(r,b)-t-1)/min(r,b)+1<k) cout<<"OBEY"<<endl;
        else cout<<"REBEL"<<endl;
    }
    return 0;
}


g c d ( a , b ) gcd(a,b) all common divisor of all factors a, b of.

The a, b factorising, g = gcd (a, b), the quality factor of the index p g = m i n ( p a , p b ) p_g=min(p_a,p_b) , So these factors make up the quality of public g, they all have these common divisor is composed of prime factors, so the direct request of the g factor.
Portal:about the number of
questions intended to: seek a, b of the total number of convention

#include<bits/stdc++.h>
using namespace std;
set<long long> st;
int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    long long Gcd=__gcd(a,b);
    long long t=sqrt(Gcd);
    for(int i=1;i<=t;++i){
        if(Gcd%i==0){
            st.insert(i);
            if(Gcd/i!=i) st.insert(Gcd/i);
        }
    }
    set<long long > ::iterator it=st.begin();
    for(;it!=st.end();++it){
        cout<<*it<<" ";
    }
    return 0;
}


Portal: A. Good OL 'a Numbers Coloring

meaning of the questions: can x a + y b x * a + y * b No sign painted white, the other black, assuming infinite 1- brands, brands whether black infinite
Solution: x a + y b = k g c d ( a , b ) x*a+y*b=k*gcd(a,b) if finite black sign, at a certain position after the start k g , k g + 1 , k g + 2...... k*g,k*g+1,k*g+2... ... Are white, x a + y b x * a + y * b continuous need g c d ( a , b ) = 1 , k g c d ( a , b ) gcd(a,b)=1,k*gcd(a,b) to continuously

#include<bits/stdc++.h>
using namespace std;
set<int> s;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int a,b;
        s.clear();
        scanf("%d%d",&a,&b);
        if(__gcd(a,b)==1){
            cout<<"Finite"<<endl;
        }
        else cout<<"Infinite"<<endl;
    }
    return 0;
}
Published 96 original articles · won praise 11 · views 2276

Guess you like

Origin blog.csdn.net/weixin_43769146/article/details/103392737
gcd