A. Counterexample (Codeforces Round #275(div2)_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:55:37
原创
1205人浏览过

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?

More specifically, you need to find three numbers (a,?b,?c), such that l?≤?a?

Input

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

立即学习前端免费学习笔记(深入)”;

Output

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.

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.

找出3个数,前两个的最大公约数为1,后两个最大公约数为1,第1个和第3个的最大公约数不为1.

由于题目中说了,r-l

代码:

#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;}
登录后复制


HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号