CF2.C
1 second
256 megabytes
standard input
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.
The single line contains single integer n (1 ≤ n ≤ 104).
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.
3
2 7 42
7
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的更多相关文章
- 代码问题:【CF2】
[CF2/CFCF/HCF]: C Ma, JB Huang, X Yang, et al. Hierarchical convolutional features for visual tracki ...
- CF2.D
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- CF2.E
E. Comments time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- CF2.D 并查集+背包
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...
- CF2.BC
B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit ...
- CF2.C(二分贪心)
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- *CF2.D(哥德巴赫猜想)
D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- cf2.25
T1 题意:判断给出的数中有多少不同的大于的数. content:傻逼题,5min手速 T2 题意:给出p.y,输出y~p+1中最大一个不是2-p的倍数的数. content:答案很简单,但是很难想到 ...
- BIRCH聚类算法原理
在K-Means聚类算法原理中,我们讲到了K-Means和Mini Batch K-Means的聚类原理.这里我们再来看看另外一种常见的聚类算法BIRCH.BIRCH算法比较适合于数据量大,类别数K也 ...
随机推荐
- 【Juicer】 一个高效、轻量的前端 (Javascript) 模板引擎
引用地址:http://juicer.name/docs/docs_zh_cn.html * 一个完整的例子 HTML 代码: <script id="tpl" type=& ...
- jQuery简单实现iframe的高度根据页面内容自适应的方法(转)
本文实例讲述了jQuery简单实现iframe的高度根据页面内容自适应的方法.分享给大家供大家参考,具体如下: 方式1: //注意:下面的代码是放在和iframe同一个页面中调用 $("#i ...
- HCP查询配置
1.配置命名空间Service里的Search功能为enable以及索引等相关配置 2.配置用户对该命名空间的查询为允许
- 【HTML5】 web上的音频
<!-- audio通过属性的设置可以控制音频播放的行为: 表6-2 audio元素的属性 ——————————————————————————————————————————————————— ...
- js == 与 === 的区别
1.对于string,number等基础类型,==和===是有区别的 1)不同类型间比较,==之比较“转化成同一类型后的值”看“值”是否相等,===如果类型不同,其结果就是不等 2)同类型比较,直接进 ...
- Oracle SqlDeveloper创建JOB
步骤1: 步骤2: 步骤3:
- IT 网址
蒋金楠 (Artech) WCF ,asp.net等 博客地址:http://www.cnblogs.com/artech/tag/WCF/ 伍华聪 ...
- 数据分析师的福音——VS 2017带来一体化的数据分析开发环境
(此文章同时发表在本人微信公众号“dotNET开发经验谈”,欢迎右边二维码来关注.) 题记:在上个月的Connect() 2016大会上,微软宣布了VS 2017 RC的发布,其中为数据分析师带来了一 ...
- 【转载】 wpf无边框的方法以及拖拽的问题
今天在做wpf程序的时候遇到了一个制作无边框的窗体并且有透明圆角的问题,我把解决的过程写下来,和大家学习 正常窗体必须把WindowStyle="None"这个属性加上去,但是加上 ...
- 没有了SA密码,无法Windows集成身份登录,DBA怎么办?
一同事反馈SQL无法正常登录了,以前都是通过windows集成身份验证登录进去的(sa密码早忘记了),今天就改了服务器的机器名,现在无论如何都登录不进去. SQL登录时如果采用windows集成身份验 ...