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)
- Codeforces Round #384(Div. 2)C. Vladik and fractions【数学】
- Codeforces Round #384 (Div. 2) C Vladik and fractions
- Codeforces Round #384 (Div. 2)-C. Vladik and fractions
- Codeforces Round #384 (Div. 2) C. Vladik and fractions
- Codeforces Round #384 (Div. 2) 743C Vladik and fractions
- Codeforces Round #384 (Div. 2) C. Vladik and fractions
- Codeforces Round #390 (Div. 2)C Vladik and chat
- Codeforces Round #416 (Div. 2)C. Vladik and Memorable Trip
- Codeforces Round #416 (Div. 2)-C. Vladik and Memorable Trip
- Codeforces Round #416 (Div. 2) C Vladik and Memorable Trip
- Codeforces Round #384 (Div. 2) A Vladik and flights
- Codeforces Round #384 (Div. 2) E. Vladik and cards
- Codeforces Round #384 (Div. 2) 743A Vladik and flights
- Codeforces Round #384 (Div. 2) E. Vladik and cards
- Codeforces Round #384 (Div. 2) A. Vladik and flights
- 【44.64%】【codeforces 743C】Vladik and fractions
- codeforces 743 C. Vladik and fractions(构造)
- 743C. Vladik and fractions codeforces
- 推荐:Zookeeper 开源客户端框架Curator简介
- linux 服务器 中脚本启动关闭 jar
- LeetCode之Remove Element
- visio studio提高工作效率的十个小技巧
- Codeforces 839A Arya and Bran (模拟)
- Codeforces Round #384 (Div. 2) C. Vladik and fractions
- bzoj 2326: [HNOI2011]数学作业(矩阵快速幂)
- 2017"百度之星"程序设计大赛
- Codeforces 839B Game of the Rows (贪心)
- subline(1):subline解决中文乱码
- parameter server学习
- Android图片保持宽高比技巧
- spring mvc高级篇(二):Spring+SpringMVC+Mybatis整合
- CPU GPU设计工作原理(转载)