A. Counterexample
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The single line contains two positive space-separated integers lr (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Output

Print three positive space-separated integers abc —
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.

Sample test(s)
input
2 4
output
2 3 4
input
10 11
output
-1
input
900000000000000009 900000000000000029
output
900000000000000009 900000000000000010 900000000000000021
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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
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;
}

A. Counterexample (Codeforces Round #275(div2)的更多相关文章

  1. B. Friends and Presents(Codeforces Round #275(div2)

    B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. C. Diverse Permutation(Codeforces Round #275(div2)

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  4. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  5. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  6. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  7. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  8. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  9. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

随机推荐

  1. 使用grep恢复被删文件内容

    在Unix/Linux下,最危险的命令恐怕就属rm命令了,每次在root下使用这个命令的时候,我都要盯着命令行看上几分钟才敢把回车敲下去.以前,看到同事在脚本中使用rm命令 —— rm {$App_D ...

  2. nginx last 和break redirect 和 permanent

    一.last & break (1)last 和 break 当出现在location 之外时,两者的作用是一致的没有任何差异. 注意一点就是,他们会跳过所有的在他们之后的rewrite 模块 ...

  3. [转]java调用外部程序Runtime.getRuntime().exec

    Runtime.getRuntime().exec()方法主要用于执行外部的程序或命令. Runtime.getRuntime().exec共有六个重载方法: public Process exec( ...

  4. JavaScript 如何从引用类型(Array 、 Object)创建一个新的对象

    数组的增删改 1.新增一项可以使用concat方法,它不会对原有数组进行改动,而是创建一个新数组 let a = [0, 1, 2] let b = a.concat([3]) console.log ...

  5. Spring Hibernate JPA 联表查询 复杂查询(转)

    今天刷网,才发现: 1)如果想用hibernate注解,是不是一定会用到jpa的? 是.如果hibernate认为jpa的注解够用,就直接用.否则会弄一个自己的出来作为补充. 2)jpa和hibern ...

  6. 在 Mac 上使用多点触控手势

    使用多点触控触控板或妙控鼠标,可以通过轻点.轻扫.捏合或开合一根或多根手指进行有用的操作. 触控板手势 有关这些手势的更多信息,请选取苹果菜单 () >“系统偏好设置”,然后点按“触控板”.您 ...

  7. 基础005_V7-Select IO

    主要参考ug471.pdf.

  8. Android:相机适配及图片处理的一些问题

    链接:http://www.cnblogs.com/liushilin/p/6387263.html 链接:http://www.cnblogs.com/liushilin/p/5956691.htm ...

  9. 快速开方法(c语言)译文

    人们最早就在Quake3源代码中发现了类似如下的C代码,它可以快速的求1/sqrt(x),在3D图形向量计算方面应用很广. float invSqrt(float x) { float xhalf = ...

  10. 解决方案:android monkeyrunner:Timeout while trying to create chimp mananger(device = MonkeyRunner.waitForConnection()一直报错的问题)

    monkeyrunner在执行device = MonkeyRunner.waitForConnection()一直报错的问题 (或者[main] [com.android.chimpchat.adb ...