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)
  • 相关阅读:
    Django入门
    初识json
    回来了
    python学习
    JavaScript 中获取元素样式
    浏览器检测与特征检测
    DOM 节点的类型及判定
    浏览器的控制台工具
    .htaccess 配置文件的使用
    workLog:07001:补充0829 前
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11794335.html
Copyright © 2011-2022 走看看