codeforces Round #275(div2) A解题报告

A. Counterexample
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

The single line contains two positive space-separated integers lr (1 ≤ l ≤ r ≤ 1018r - l ≤ 50).

Output

Print three positive space-separated integers abc — 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.

Sample test(s)
input
2 4
output
2 3 4
input
10 11
output
-1
input
900000000000000009 900000000000000029
output
900000000000000009 900000000000000010 900000000000000021
Note

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.

题目大意:

给一个范围,l和r,求出该范围内的三个数字,要求符合 gcd(a, b) = gcd(b, c) = 1,  gcd(a, c) != 1

解法:

看似数据很大,但是范围很小,只有50,枚举就可以做出来了

代码:

#include <iostream>
#define LL long long

using namespace std;

LL l, r;

LL gcd(LL a, LL b) {
	return b ? gcd(b, a%b) : a;
}

void init() {
	cin >> l >> r;
}

void solve() {
	for (LL i = l; i <= r; i++)
		for (LL j = i+1; j <= r; j++)
			for (LL k = j+1; k <= r; k++)
				if (i != j && j != k && i != k)
					if (gcd(i, j) == 1 && gcd(j, k) == 1 && gcd(i, k) != 1) {
						cout << i << ' ' << j << ' ' << k << endl;
						return;
					}

	cout << "-1" << endl;
}

int main() {
	init();
	solve();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值