• Codeforces 743C


    Codeforces Round #384 (Div. 2)

    题目链接:Vladik and fractions

    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 (frac{2}{n}) as a sum of three distinct positive fractions in form (frac{1}{m}).

    Help Vladik with that, i.e for a given (n) find three distinct positive integers (x, y) and (z) such that (frac{2}{n} = frac{1}{x} + frac{1}{y} + frac{1}{z}). Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding (10^9).

    If there is no such answer, print (-1).

    Input

    The single line contains single integer (n (1 le  n le  10^4)).

    Output

    If the answer exists, print 3 distinct numbers (x, y) and (z (1 le  x, y, z le  10^9, x  eq y, x  eq  z, y  eq  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
    

    Solution

    题意

    给定一个正整数 (n),求正整数 (x,y,z) 满足 (frac{2}{n} = frac{1}{x} + frac{1}{y} + frac{1}{z})

    其中 (x eq y, x eq z, y eq z)。若无解输出 (-1)

    题解

    构造

    [frac{1}{n} - frac{1}{n + 1} = frac{1}{n(n+1)} ]

    [frac{1}{n} = frac{1}{n + 1} + frac{1}{n(n+1)} ]

    [frac{2}{n} = frac{1}{n + 1} + frac{1}{n(n+1)} + frac{1}{n} ]

    (n=1) 时,(frac{2}{n}=2)。而 ((frac{1}{x}+frac{1}{y}+frac{1}{z})_{max} = frac{1}{1}+frac{1}{2}+frac{1}{3} < 2),所以当 (n=1) 时无解。

    Code

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin >> n;
        if(n == 1) cout << -1 << endl;
        else cout << (n + 1) << " " << (n * (n + 1)) << " " << n << endl;
        return 0;
    }
    
  • 相关阅读:
    TDD测试驱动开发
    力导向算法研究
    简单软件破解入门
    学习Go语言之模板方法模式
    学习Go语言之观察者模式
    学习Go语言之使用channel避免竞态问题
    学习Go语言之使用原子访问或互斥锁解决竞态问题
    使用 Beego 搭建 Restful API 项目
    学习Go语言之抽象工厂模式
    [转载]几张图看懂区块链技术到底是什么?
  • 原文地址:https://www.cnblogs.com/wulitaotao/p/11455937.html
Copyright © 2020-2023  润新知