CodeForces#275--DIV 2--A
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.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio> using namespace std; long long gcd(long long x, long long y)
{
if(!x || !y) return x > y ? x : y; for(long long t; t = x%y; x = y, y = t); return y;
} long long kgcd(long long a, long long b)
{
if(a < b)
swap(a, b);
if(a == 0) return b; if(b == 0) return a; if(!(a&1) && !(b&1))
return kgcd(a>>1, b>>1) << 1;
else if(!(b & 1))
return kgcd(a, b>>1);
else if(! (a & 1))
return kgcd(a>>1, b);
else
return kgcd(b, a - b);
} int main()
{
long long l, r;
while(cin >> l >> r)
{
long long a, b, c;
bool tag = false;
///暴力枚举
for(a = l; a < r; a++)
{
for(b = a + 1; b < r; b++)
{
for(c = b + 1; c <= r; c++)
{
if(kgcd(a, c) != 1 && kgcd(a, b) == 1 && kgcd(b, c) == 1)
{
tag = true;
cout << a << " " << b << " " << c << endl;
break;
}
}
if(tag == true)
break;
}
if(tag == true)
break;
} if(tag == false)
cout << -1 << endl;
} return 0;
}
试着又复习了下GCD KGCD
CodeForces#275--DIV 2--A的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- 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 #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- codeforces #577(Div.2)
codeforces #577(Div.2) A Important Exam A class of students wrote a multiple-choice test. There are ...
随机推荐
- mysql my.cnf配置文件详解
本配置文件针对Dell R710,双至强E5620.16G内存的硬件配置.CentOS 5.6 64位系统,MySQL 5.5.x 稳定版.适用于日IP 50-100w,PV 100-300w的站点, ...
- 晨跑(bzoj 1877)
Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...
- Mysql之INFORMATION_SCHEMA解析1
INFORMATION_SCHEMA库是Mysql提供的一个系统库,保存了数据库的原数据,方便用户监控与管理Msyql. 现在单说与INNODB相关的库:INNODB_SYS_TABLES,INNOD ...
- MongoDB C API
一.编译mongodb c driver: 编译完成之后在c:\mongo-c-driver目录下有bin.include.lib三个文件夹,分别包含所需的dll..h文件.lib. 在自己的项目中引 ...
- iOS-OC-基本控件之UITextField
UITextField IOS开发中必不可少的基本控件,本文主要是列出常用的属性及方法(注XCode版本为7.2) 文本框,可以理解为输入框或者显示框,即用户可以往里面输入文字或图片,可以输入当然也可 ...
- php 关联数据库的留言板练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- centos vsftp 服务器配置
安装服务端: # yum install -y vsftpd 安装客服端: # yum install ftp -y http://os.51cto.com/art/201408/448630.htm
- volatile关键字与线程间通信
>>Java内存模型 现在计算机普遍使用多处理器进行运算,并且为了解决计算机存储设备和处理器的运算速度之间巨大的差距,引入了高速缓存作为缓冲,缓存虽然能极大的提高性能,但是随之带来的缓存一 ...
- Linux Shell 高级编程技巧2----shell工具
2.shell工具 2.1.日志文件 简介 创建日志文件是很重要的,记录了重要的信息.一旦出现错误,这些信息对于我们排错是非常有用的:监控的信息也可以记录到日 ...
- C#在excel中添加超链接
1.新建一个项目 2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本) using Excel = Microsoft.Office.Inter ...