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. .net MVC 简单图片上传

    主要完成的是在网页上 上传一张图片到服务器 我搜出来的上传文件代码都特别复杂,对于初学者来说,先解决能上传的问题才最重要,并不需要特别多的功能,仅适合不会上传的初学者,大神请绕路,错误请指出,谢谢 v ...

  2. oracleDBA-D4

    1.数据字典: 创建和维护的可修改的系统表..它存放有关数据库和数据库对象的信息. 数据字典=基表+字典视图 2.数据字典所存放的信息: 数据库的逻辑和物理结构(如:表空间和数据文件),数据对象定义的 ...

  3. linux I/O复用

    转载自:哈维.dpkirin url:http://blog.csdn.NET/zhang_shuai_2011/article/details/7675797 http://blog.csdn.Ne ...

  4. java 代码解压7z(带密码)转载请注明出处,谢谢

    <sevenzipjbinding.version>9.20-2.00beta</sevenzipjbinding.version> <dependency> &l ...

  5. LInux Shell 快捷键

    CTRL 键相关的快捷键: Ctrl + a - Jump to the start of the lineCtrl + b - Move back a charCtrl + c - Terminat ...

  6. Mac eclipse配置Python环境

    1.给Eclipse安装PyDev插件 第一次启动会让选择一个工作空间,按缺省设置,勾选一下不再提醒,就可以了.在Help菜单中,选择Install New Software···, 选择Add按钮, ...

  7. html表单提交方式

    xml 表单提交方式: * 使用submit提交 <form> 要提交的数据 <input type="submit" /'> </form> ...

  8. design包 TabLayout使用

    类似"网易新闻"UI设计就很好,顶部是导航,下面是各个页面.如图 这种效果使用design包中的TabLayout可以轻松的实现.   一.分析TabLayout 常见 UI 上图 ...

  9. elasticsearch5.0.0 安装插件及配置过程

    elasticsearch5.0.0 安装插件及配置过程 由于es5.0是里程碑式的更新,所以很多变化的地方,暂时我就插件安装遇到的问题记录一下. 插件安装命令 2.3版本的安装命令 安装Marvel ...

  10. 【干货】jsMind思维导图整合Easyui的右键菜单

    原材料: 1.web版本的JavaScript思维导图(BSD开源协议)[戳这里去官网]. 2.easyui最新版[戳这里去官网]. 这里是原本的jsMind: 在线测试地址 :http://hizz ...