zoukankan      html  css  js  c++  java
  • Codeforces Round #275 (Div. 2)-A. Counterexample

    http://codeforces.com/contest/483/problem/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.

    解题思路:因为r-l <= 50,所以三重for循环暴力即可

     1 #include <stdio.h>
     2 
     3 #define ll long long
     4 
     5 ll gcd(ll a, ll b){
     6     ll t;
     7     while(b > 0){
     8         t = a % b; a = b; b = t;
     9     }
    10     return a;
    11 }
    12 
    13 int main(){
    14     ll a, b, c, l, r, i, j, k;
    15     int flag;
    16     while(scanf("%I64d %I64d", &l, &r) != EOF){
    17         flag = 0;
    18         for(i = l; i < r - 1; i++){
    19             a = i;
    20             for(j = i + 1; j < r; j++){
    21                 b = j;
    22                 for(k = j + 1; k <= r; k++){
    23                     c = k;
    24                     if(gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(a, c) != 1){
    25                         flag = 1;
    26                     }
    27                     if(flag == 1break;
    28                 }
    29                 if(flag == 1break;
    30             }
    31             if(flag == 1break;
    32         }
    33         if(flag == 1){
    34             printf("%I64d %I64d %I64d ", a, b, c);
    35         }
    36         else{
    37             printf("-1 ");
    38         }
    39     }
    40     return 0;

    41 } 

  • 相关阅读:
    spart快速大数据分析学习提纲(一)
    Zookeeper的设计模式之观察者模式(十)
    shuffle机制和TextInputFormat分片和读取分片数据(九)
    MapReduce程序开发之流量求和(八)
    分布式系统间通信之RPC简单Demo(七)
    使用JAVA客户端对HDFS进行代码编写(五)
    分布式系统间通信之RPC的基本概念(六)
    DataNode工作原理(四)
    NameNode元数据的管理机制(三)
    javaweb项目部署到服务器(树莓派)上全过程——部署步骤记录与总结
  • 原文地址:https://www.cnblogs.com/angle-qqs/p/4063505.html
Copyright © 2011-2022 走看看