Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.
You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.
More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair(a, c) is not coprime.
The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).
Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1.
2 4
2 3 4
10 11
-1
900000000000000009 900000000000000029
900000000000000009 900000000000000010 900000000000000021
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.
题意:给你l,r,让你求a,b,c,l<=a<b<c<=r,并且是gcd(a,b)=1,gcd(b,c)=1,但是gcd(a,c)!=1,因为r-l<=50所以直接爆搜就好。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include<ctime>
#define esp 1e-6
#define LL long long
#define inf 0x0f0f0f0f
using namespace std;
__int64 gcd(__int64 da,__int64 xiao) {
if (da%xiao==0)
{
return xiao;
}
else
{
return gcd(xiao,da%xiao);
} }
int main()
{
__int64 l,r;
__int64 a,b,c,i,j,k;
int flag;
while(scanf("%I64d%I64d",&l,&r)!=EOF)
{
flag=0;
for(a=l;a<=r;a++)
for(b=a+1;b<=r;b++)
for(c=b+1;c<=r;c++)
{
if(gcd(a,b)==1&&gcd(b,c)==1&&gcd(a,c)!=1)
{
flag=1;
goto loop;
}
}
loop:
if(flag==1)
printf("%I64d %I64d %I64d\n",a,b,c);
else
printf("-1\n");
}
}