A. Counterexample (Codeforces Round #275(div2)
1 second
256 megabytes
standard input
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.
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.
找出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)的更多相关文章
- 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 ...
- C. Diverse Permutation(Codeforces Round #275(div2)
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- 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 ...
- 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
随机推荐
- 使用ShellExecute打开文件夹并选中文件
原文链接: http://futurecode.is-programmer.com/posts/24780.html 假设在C:\目录下存在文件a.txt. 打开这个目录是ShellExecute的常 ...
- [转]在windows上实现多个java jdk的共存解决办法
问题背景 公司项目中应用到的jdk环境为1.6,最近在家学习IntelliJ IDEA中sdk多环境配置时,想安装Jdk1.8,作为学习基础.那么问题来了,公司项目扩展不支持jdk1.8,为了既能满足 ...
- mongodb 数据库操作--备份 还原 导出 导入(转)
mongodb 数据库操作--备份 还原 导出 导入 -------------------MongoDB数据导入与导出------------------- 1.导出工具:mongoexport ...
- 基础004_V7-DSP Slice
主要参考ug479.pdf.之前的文章:FIR调用DSP48E_05.本文主要记录基本用法. 一.DSP48核 A-参数说明 instrctions,多个功能,通过sel选用 目前没发现C勾选与否,有 ...
- python 并发编程(socketserver)
下面的例子是简单的ssh 登录,其实也就是客户端把指令发送给服务器.服务器把结果返还给客户端,客户端再在终端展现 服务端代码: #Author:BigBao #Date:2018/7/18 # 我们之 ...
- Python 3 的安装
python 3 的安装: 背景: 之前都是在Pychram上写,我的windows下的python版本是3.5,今天要把一个小脚本上到生产环境上. 无奈我服务器上的python版本是2.6.6.所以 ...
- android sqlite3:数据库操作
1. 修改表名: alter table notification rename to notification_test 2. 修改数据库名称: 3. 复制一个表的数据到另外一个表中(表的字段一致) ...
- Java常考面试题(五)
序言 好好努力. ---WH 一.Iterator和ListIterator的区别是什么? 自我解答: Iterator是针对所有collection来使用的,而看名字ListIterator,顾名思 ...
- 【Unity】7.1 Input类的方法和变量
分类:Unity.C#.VS2015 创建日期:2016-04-21 一.简介 在Input类中,Key与物理按键对应,例如键盘.鼠标.摇杆上的按键,其映射关系无法改变,程序员可以通过按键名称或者按键 ...
- 菜鸟调错(三)——Jboss与jdk版本不兼容导致WebService调用出错
环境: jdk1.6 Jboss 5.1.0.GA 问题描述: EJB发布webserivce已经成功,并且能够成功访问wsdl文件: 使用axis1自带的sample/client下的类Dynami ...