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 ...
随机推荐
- 操作系统 Lab1(2)
中断很久,一看发现又多了一些内容. 打算完成了 Lab1 challenge 1 中断像量表设置的时候我们需要设置一个用于系统调用的 trap门 也就是 利用中断切换特权级 To kernel 调用 ...
- VC++中文件读写汇总
1,读 A法: CString strFileName = "C:\\dd.txt"; std::ifstream in; std::locale::global(std::loc ...
- springboot整合rabbitMQ时遇到的消息无法入列问题
问题描述: 对列和交换器配置如下(绑定的正常交换器的key是“convert”): 管理平台上手动发是可以的: 而通过程序发消息不行,根本没有进入队列: 解决:显式指定交换器(备选交换器和死信交换器都 ...
- LUOGU NOIP 2018 模拟赛 DAY1
T1 传送门 解题思路 这似乎是小学数学知识???mod 9就相当于各位之和mod 9,打表求了个逆元,等差数列求和公式就行了. #include<iostream> #include&l ...
- webpack 处理图片文件
1. 安装 file-loader html-loader npm install file-loader html-loader --save-dev 其中html-loader生效需配合 html ...
- Extjs4 的一些语法 持续更新中
一.给GridPanel增加成两行toolbar tbar: { xtype: 'container', layout: 'anchor', defaults: {anchor: '0'}, defa ...
- SQL2005自动备份,定期删除的维护计划及自动定期清除日志
作为一名DBA,他们最常见的日常任务是: 1)定期完成数据库的完全备份或差异备份.2)定期清理备份文件,因为存储空间有限,可能只需要保存一个时期段内的文件(比如一周内或一月内). 而如何做到这两点呢? ...
- 关于JEECMS套站工具的使用要点
第一步:在[界面—资源]下面引入资源文件(js,css,img…) 第二步:在[界面—模板]下面将网站的入口页面写在[index]文件下 此时修改index页面中的 js,css,图片 的路径,路 ...
- Jquery选择器总结二
简单选择器 1.:firstè选出匹配的元素中的第一个 2.:lastè选出匹配的元素中的最后一个 3.:eq(index)è选出匹配的元素中的指定索引位置的jquery对象(注:index从0开始) ...
- HDFS应用实例