C. Vladik and fractions
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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,问有没有三个数x,y,z,使得1/x+1/y+1/z=2/n;

代码:

 //直接模拟,枚举比2/n小的分数,从1/(n/2+1)开始到2/n-1/(n/2+1)结束,这样依次得到x,y,z,记住分子分母要约分要
//防止超过1e9,判断x,y,z是否符合条件即可。
#include<bits\stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y)
{
if(y==) return x;
return gcd(y,x%y);
}
int main()
{
int n;
while(cin>>n)
{
if(n==)
{
cout<<"-1\n";
continue;
}
ll f1,f2,maxn,minn,f3,f4,x,y,z;
if(n&)
{
f1=;f2=n;
}
else
{
f1=;f2=n/;
}
minn=(f2+)/f1;
maxn=f2*minn;
int flag=;
for(ll i=minn;i<=maxn;i++)
{
x=i;
f4=i*f2;
f3=f1*i-f2;
ll cnt=gcd(f4,f3);
f4/=cnt;f3/=cnt;
y=(f4+)/f3;
z=y*f4;
ll tem=f3*y-f4;
cnt=gcd(z,tem);
z/=cnt;tem/=cnt;
if(x==y||x==z||z==y||tem!=||x<=||y<=||z<=||z>1e9||y>1e9||z>1e9)
continue;
flag=;
break;
}
if(flag) cout<<x<<" "<<y<<" "<<z<<endl;
else cout<<"-1\n";
}
return ;
}
//本题这样做就麻烦了,其实只有n=1时不能拆成三个分数相加,其余的数都可以拆成1/n,1/(n+1),1/n*(n+1);
#include<bits\stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==) cout<<"-1\n";
else
cout<<n<<" "<<n+<<" "<<n*(n+)<<endl;
return ;
}

CF2.C的更多相关文章

  1. 代码问题:【CF2】

    [CF2/CFCF/HCF]: C Ma, JB Huang, X Yang, et al. Hierarchical convolutional features for visual tracki ...

  2. CF2.D

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  3. CF2.E

    E. Comments time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. CF2.D 并查集+背包

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...

  5. CF2.BC

    B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit ...

  6. CF2.C(二分贪心)

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. *CF2.D(哥德巴赫猜想)

    D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  8. cf2.25

    T1 题意:判断给出的数中有多少不同的大于的数. content:傻逼题,5min手速 T2 题意:给出p.y,输出y~p+1中最大一个不是2-p的倍数的数. content:答案很简单,但是很难想到 ...

  9. BIRCH聚类算法原理

    在K-Means聚类算法原理中,我们讲到了K-Means和Mini Batch K-Means的聚类原理.这里我们再来看看另外一种常见的聚类算法BIRCH.BIRCH算法比较适合于数据量大,类别数K也 ...

随机推荐

  1. 定时器管理:nginx的红黑树和libevent的堆

    libevent 发生超时后, while循环一次从堆顶del timer——直到最新调整的最小堆顶不是超时事件为止,(实际是del event),但是会稍后把这个timeout的 event放到ac ...

  2. 获取文本的编码类型(from logparse)

    import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...

  3. POJ 2823 Sliding Window 线段树区间求和问题

    题目链接 线段树区间求和问题,维护一个最大值一个最小值即可,线段树要用C++交才能过. 注意这道题不是求三个数的最大值最小值,是求k个的. 本题数据量较大,不能用N建树,用n建树. 还有一种做法是单调 ...

  4. gulp学习-gulpfile

    安装gulp 假设已经安装了node 和npm (淘宝的cnpm很适合国内使用). 1.首页全局安装gulp. 1 npm install --global gulp 2.其次局部安装gulp.(注: ...

  5. json 序列化为数组

    我们通常从后台取到json格式的数据到前台进行展示,在这个过程中可能户遇到一些json格式不是自己想要的格式,今天本人就遇到一个棘手的问题,最后在师傅的协助下才进行了正确格式的转换. 可以说最悲哀的莫 ...

  6. C#设计模式之建造者模式

    建造者模式可以将部件本身和它们的组装过程分开,关注如何一步步创建一个包含多个组成部分的复杂对象,用户只需要指定复杂对象的类型即可得到该对象,而无须知道其内部的具体构造细节. 建造者模式:将一个复杂对象 ...

  7. JAVA图片验证码

    package hh.com.util; import java.io.IOException; import javax.servlet.ServletException; import javax ...

  8. R3.2.2安装

  9. Android基础学习第三篇—Intent的用法

    写在前面的话: 1. 最近在自学Android,也是边看书边写一些Demo,由于知识点越来越多,脑子越来越记不清楚,所以打算写成读书笔记,供以后查看,也算是把自己学到所理解的东西写出来,献丑,如有不对 ...

  10. 【Java EE 学习 69 上】【struts2】【paramsPrepareParamsStack拦截器栈解决model对象和属性赋值冲突问题】

    昨天有同学问我问题,他告诉我他的Action中的一个属性明明提供了get/set方法,但是在方法中却获取不到表单中传递过来的值.代码如下(简化后的代码) public class UserAction ...