zoukankan      html  css  js  c++  java
  • Codeforces Round #384 (Div. 2) C. Vladik and fractions

    C. Vladik and fractions
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .

    Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can’t check Vladik’s answer if the numbers are large, he asks you to print numbers not exceeding 109.

    If there is no such answer, print -1.

    Input
    The single line contains single integer n (1 ≤ n ≤ 104).

    Output
    If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1.

    If there are multiple answers, print any of them.

    Examples
    input
    3
    output
    2 7 42
    input
    7
    output
    7 8 56
    题意:输入一个n,使等式2/n=1/x+1/y+1/z成立(x!=y!=z),输出x,y,z,如果不存在,输出-1,n值小于1e4。

    题解:满足这个方程的解有多个,三层暴力肯定会炸,因此从等式入手。根据已知的n可得2/n,拆分2/n可得1/n+1/n,因为三个数不相等,继续可以将其中一个1/n拆分成[1/(n+1)]+[1/n*(n+1)],最后可得三个不同的分母,n,n+1,n*(n+1)。直接输出即可。注意当n=1时是不可能由三个分子是1,分母不同的三个分数加和得到的,也就是特判输出-1。

    #include<stdio.h>
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(n==1)
            {
                printf("-1
    ");
                continue;
            }
            printf("%d %d %d
    ",n,n+1,n*(n+1));
        }
    }
    ///给一个n,求2/n=1/x+1/y+1/z中的x y z,解有多个
    ///2/n=1/n+1/n,但是因为x!=y!=z
    ///所以把其中一个1/n又可以分解成[1/(n+1)]+[1/n*(n+1)]
    ///因此最后结果是n  n+1   n*(n+1)
  • 相关阅读:
    WinSCP命令行操作
    Android SDK platforms build-tools等镜像下载
    Ubuntu 18.04 下配置 HAXM 加速 Android模拟器
    HDU 2222 Keywords Search
    获取Android自己写好了的apk以及反编译
    Linux下几个常用的快捷键,真的很实用
    Android项目实战--手机卫士18--读取用户的短信内容以及短信备份
    高仿“点触验证码”做的一个静态Html例子
    我的华为面试经历——技术服务
    数据库日期类型转换–HSQL
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11794335.html
Copyright © 2011-2022 走看看