当前位置:Gxlcms > mysql > A.Counterexample(CodeforcesRound#275(div2)

A.Counterexample(CodeforcesRound#275(div2)

时间:2021-07-01 10:21:17 帮助过:44人阅读

Note In the first sample pair (2,?4) is not coprime and pairs (2,?3) and (3,?4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000

Note

In the first sample pair (2,?4) is not coprime and pairs (2,?3) and (3,?4) are.

In the second sample you cannot form a group of three distinct integers, so the answer is -1.

In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

找出3个数,前两个的最大公约数为1,后两个最大公约数为1,第1个和第3个的最大公约数不为1.

由于题目中说了,r-l<=50,可以直接O(n^3)暴力做。

代码:

#include 
#include 
#include 
#include 
using namespace std;
long long gcd(long long a,long long b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    long long l,r;
    long long x,y,z;
    int sign=0;
    scanf("%I64d%I64d",&l,&r);
    for(long long i=l;i<=r;i++)
    {
        for(long long j=i+1;j<=r;j++)
        {
            for(long long k=j+1;k<=r;k++)
            {
                if(gcd(i,j)==1&&gcd(j,k)==1&&gcd(i,k)!=1)
                {
                    x=i;
                    y=j;
                    z=k;
                    sign=1;
                    break;
                }
            }
            if(sign)
            break;
        }
        if(sign)
        break;
    }
    if(sign)
    printf("%I64d %I64d %I64d\n",x,y,z);
    else
    printf("-1\n");
    return 0;
}

人气教程排行