zoukankan      html  css  js  c++  java
  • Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】

    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 ≤ 1018; r - 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.

    Examples
    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.

    【题意】:是否存在连续的序列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
    ",x,y,z);//
        else printf("-1
    ");
    }
    

      

  • 相关阅读:
    数据不是搜集起来的,是沉淀下来的,跟脚印一样,脚印不是修路的人搜集起来的,只要有了路就一定有脚印,不可能说修一条路不留下脚印,世界上没有这样的路
    VC6.0编译的DLL文件能否反编译知道里面的代码?
    Why does the PDB format change every release?
    mysql_query与 mysql_real_query区别
    如何把Backtrack 5安装到U盘/Backtrack 4安装方法
    FreeBSD:像Linux下一样使用vim
    栈的出栈序列个数
    npm outdated -g --depth=0
    npm Updating packages downloaded from the registry
    TypeScript安装
  • 原文地址:https://www.cnblogs.com/Roni-i/p/8011857.html
Copyright © 2011-2022 走看看