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)
  • 相关阅读:
    作业20170928--2 单元测试
    作业20170928—1代码规范,结对要求
    第三周PSP
    20170922-3 功能测试作业
    第二周PSP
    采用c#实现功能1
    linux下搭建生成HLS所需的.ts和.m3u8文件
    android编译ffmpeg+x264
    ubuntu.sh: 113: ubuntu.sh: Syntax error: "(" unexpected
    解决:[WARNING] fpm_children_bury(), line 215: child 2736 (pool default) exited on signal 15 SIGTERM after 59.588363 seconds from start
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11794335.html
Copyright © 2011-2022 走看看