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. 导入excel

    1.js使用ajaxfileupload.js实现文件上传 2.将文件转为字节 3.将字节转为excel保存到服务器 4.根据路径读取excel文件并转为dataSet 5.将dataSet写入数据库

  2. SpringMVC文件上传和下载

    上传与下载 1文件上传 1.1加入jar包 文件上传需要依赖的jar包 1.2配置部件解析器 解析二进制流数据. <?xml version="1.0" encoding=& ...

  3. Thread比Task多出的无法代替的部分

    Task比Thread耗资源更少,且默认在线程池中. 但是Thread能够设置为STA来执行而Task不能,这对于某些特殊功能很重要,比如WebBrowser控件对象就不能在非单线程单元的线程中new ...

  4. iOS 自动追加版本时间版本号脚本

    buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${PROJECT_DIR}/${I ...

  5. 三、线程同步之Sysnchronized关键字

    线程同步 问题引入 观察一面一段小程序: public class Main { private static int amount = 0; public static void main(Stri ...

  6. 使用git grep进行git搜索

    1.git grep foo 会自动map所有包含foo的文件 2.git grep -n foo  显示行号 3.git grep --name-only foo 只显示文件名 4.git grep ...

  7. d3 中exit() remove()正确工作的方式

    在官网中给出的代码[1]是有问题的,如下的代码并不能正常工作: // Update… var p = d3.select("body").selectAll("p&quo ...

  8. Redis集群搭建1

    wget .168.0.201:6379 192.168.0.201:6380 192.168.0.201:6381 192.168.0.202:16379 192.168.0.202:16380 1 ...

  9. [NHibernate]利用LINQPad查看NHibernate生成SQL语句

    上篇文章中我们提到可以通过重写NHibernate的 EmptyInterceptor 拦截器来监控NHibernate发送给数据库的SQL脚本,今天看到有朋友用LINQPad工具来进行NHibern ...

  10. adt_sdk_tools介绍

    draw9patch.bat hierarchyviewer.bat traceview.bat