The name of u000083 is in harmony, and the name of u000083 is in harmony.

Source: Internet
Author: User

The name of u000083 is in harmony, and the name of u000083 is in harmony.
Background

We all know that g is the approximate number of a. if and only when g is positive and a mod g = 0.

As we all know, if g is a divisor of a and B, we call g a common divisor of a and B.

As we all know, the largest common divisor of a and B is called the largest common divisor.

Description

For the given two positive integers a and B, you need to find their next-largest common divisor ).

Input/output format:

 

The first line has two positive integers a and B.

 

Output Format:

 

The first line is a number, which indicates the next big approximate number of a and B. If there is only one common divisor for a and B,-1 is output.

 

Input and Output sample input sample #1:
2 3
Output sample #1:
-1
Description

Test Point 1. 4: a, B ≤ 10 ^ 5

Test Point 1 .. 10≤ a, B ≤ 10 ^ 9

This question is about the next big common appointment. We can YY it. When we know the maximum common Appointment of a number, the next big appointment must be the maximum common appointment/its minimum prime factor, however, this question allows us to calculate the number of the two numbers, so we don't need to screen the prime number. After all, we can directly scan for the O (n), and the sieve prime number is also O (n) but... 1 is also the common number of two numbers !!!!!!!!!!! I am very young.
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 using namespace std; 7 const int MAXN=2000001; 8 const int INF = 1e8; 9 inline void read(int &n)10 {11     char c='+';int x=0;bool flag=0;12     while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}13     while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();}14     n=flag==1?-x:x;15 }16 int fir;17 int sed;18 int ans;19 bool flag;20 int gcd(int a,int b)21 {22     if(b==0)    return a;23     else     return gcd(b,a%b);24 }25 int main()26 {27     //freopen("a.in","r",stdin);28     //freopen("c.out","w",stdout);29     int a,b;30     read(a);read(b);31     int g=gcd(a,b);32     for(int i=2;i<=g-1;i++)33         if(g%i==0)34         {35             ans=g/i;36             break;37         }38     if(ans==0&&g!=1)    cout<<"1";39     else cout<<(ans==0?-1:ans);40     return  0;41 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.