Codeforces Round #384 (Div. 2) C. Vladik and fractions

来源:互联网 发布:openbugs软件 编辑:程序博客网 时间:2024/05/21 08:58

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\n");            continue;        }        printf("%d %d %d\n",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)
阅读全文
0 0