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\)的矩阵可 ...
随机推荐
- logstash_output_mongodb插件用途及安装详解
安装详情参见:http://mojijs.com/2017/03/222639/index.html http://www.jianshu.com/p/8516e51e105d
- linux记录sftp命令
使用以下配置方法不需要配置chroot. 编辑sshd_config文件 vi /etc/ssh/sshd_config 增加: Subsystem sftp /usr/libexec/openssh ...
- 什么是Web缓存控制(基于HTTP头域)
这是一篇转载的知识性的文档,主要目的是为了让Web缓存相关概念更容易被开发者理解并应用于实际的应用环境中.为了简要起见,某些实现方面的细节被简化或省略了.如果你更关心细节实现则完全不必耐心看完本文,后 ...
- Android自带的TTS功能
在Android1.6之后添加了TextToSpeech,也叫TTS,把相应的文字转化成语音播报,增强了用户体验.可以根据语言播报 界面上的控件如下: 可以选择的语言 但有的语言不支持,比如中文就不支 ...
- C#基础第六天-作业-利用面向对象的思想去实现名片
1.利用面向对象的思想去实现: (增加,修改,删除,查询,查询全部)需求:根据人名去(删除/查询).指定列:姓名,年龄,性别,爱好,电话. 本系列教程: C#基础总结之八面向对象知识点总结-继承与多态 ...
- application配置和profile隔离配置(转)
前言 github: https://github.com/vergilyn/SpringBootDemo 说明:我代码的结构是用profile来区分/激活要加载的配置,从而在一个project中写各 ...
- Java获取请求客户端的真实IP地址
整理网友的材料,最后有源码,亲测能解决所有java获取IP真实地址的问题 整理的这里: 1.链接1 2.链接2 JSP里,获取客户端的IP地址的方法是: request.getRemoteAddr() ...
- nginx配置ssl双向证书
CA根证书制作 # 创建CA私钥 openssl genrsa -out ca.key 2048 #制作CA根证书(公钥) openssl req -new -x509 -days 3650 -key ...
- 将redis作为windows服务安装
1,下载redis并解压到一个目录下,然后切换到该目录下,也就是redis-server.exe文件所在的目录 2,在cmd下执行 redis-server --service-install red ...
- angular学习笔记(三十一)-$location(1)
本篇介绍angular中的$location服务的基本用法,下一篇介绍它的复杂的用法. $location服务的主要作用是用于获取当前url以及改变当前的url,并且存入历史记录. 一. 获取url的 ...