Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】
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.
【题意】:是否存在连续的序列a b c 满足a和b以及b和c最大公约数为1,而a和c最大公约数不为1。
【分析】:3重for循环暴力枚举,注意不要爆int,都要long long
【代码】:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 65535+10
ll x,y,z;
int f;
ll gcd(ll a ,ll b)
{
return b?gcd(b,a%b):a;
} int main()
{
ll n,m;
f=0;
cin>>n>>m;
for(ll i=n;i<=m;i++)
{
for(ll j=i+1;j<=m;j++)
{
for(ll k=j+1;k<=m;k++)
{
if((gcd(i,j)==1)&&(gcd(j,k)==1)&&(gcd(i,k)!=1))
{
x=i;
y=j;
z=k;
f=1;
break;
}
}
if(f) break;
}
if(f) break;
}
if(f) printf("%lld %lld %lld\n",x,y,z);//
else printf("-1\n");
}
Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】的更多相关文章
- Codeforces Round #275 (Div. 2)-A. Counterexample
http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...
- 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 Round #275 (Div. 2)]B - Friends and Presents
最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...
- Codeforces Round #275 (Div. 2)
A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...
- Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...
- Codeforces Round #275 (Div. 2) A,B,C,D
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #275 (Div. 2) C
题目传送门:http://codeforces.com/contest/483/problem/C 题意分析:题目意思没啥好说的. 去搞排列列举必须TLE.那么就想到构造. 1.n.2.n-1.3.n ...
随机推荐
- Redis安装过程:
- [转]C#中用NamedPipe进程间通信
转自:http://blog.csdn.net/jinjazz/archive/2009/02/03/3861143.aspx 本文只是一个测试例子,核心代码是kernel32.dll中的一组wind ...
- Odoo使用jsonrpc协议
在controller添加一个test方法, 不需参数 @http.route('/test', type = 'json', auth = 'public') def test(self): pha ...
- 关于ie11的浏览器检测
我的电脑昨天更新的时候把ie11给更新出来了,然后发现我的skylineweb项目提示我的浏览器不是ie,这样显然是浏览器检测出现了问题.查找后找到了下面的解决方法.大家的电脑如果也更新成了ie11的 ...
- Java面试总结-基础篇2
1. mvn的dependency-management dependency-management是声明依赖,不实际引入,主要用于在父依赖中统一各依赖的版本,否则,各个子模块在引用同一依赖时,难免会 ...
- gin框架中间件
1. Gin框架中间件Gin框架中间件A. Gin框架允许在请求处理过程中,加入用户自己的钩子函数.这个钩子函数就叫中间件B. 因此,可以使用中间件处理一些公共业务逻辑,比如耗时统计,日志打印,登陆校 ...
- Luogu P1712 [NOI2016]区间(线段树)
P1712 [NOI2016]区间 题意 题目描述 在数轴上有 \(N\) 个闭区间 \([l_1,r_1],[l_2,r_2],...,[l_n,r_n]\) .现在要从中选出 \(M\) 个区间, ...
- MySQL抑制binlog日志中的BINLOG部分的方法
1.mysqlbinlog之base64-output参数 --base64-output=value This option determines when events should be dis ...
- php实现的支持断点续传的文件下载类
通常来说,php支持断点续传,主要依靠HTTP协议中 header HTTP_RANGE实现. HTTP断点续传原理: Http头 Range.Content-Range()HTTP头中一般断点下载时 ...
- 唱吧基于 MaxCompute 的大数据之路
使用 MaxCompute之前,唱吧使用自建体系来存储处理各端收集来的日志数据,包括请求访问记录.埋点数据.服务器业务数据等.初期这套基于开源组件的体系有力支撑了数据统计.业务报表.风控等业务需求.但 ...