Codeforces 743C - Vladik and fractions (构造)
Codeforces Round #384 (Div. 2)
题目链接:Vladik and fractions
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 \(\frac{2}{n}\) as a sum of three distinct positive fractions in form \(\frac{1}{m}\).
Help Vladik with that, i.e for a given \(n\) find three distinct positive integers \(x, y\) and \(z\) such that \(\frac{2}{n} = \frac{1}{x} + \frac{1}{y} + \frac{1}{z}\). Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding $10^9$.
If there is no such answer, print \(-1\).
Input
The single line contains single integer \(n (1 \le n \le 10^4)\).
Output
If the answer exists, print 3 distinct numbers \(x, y\) and \(z (1 \le x, y, z \le 10^9, x \neq y, x \neq z, y \neq 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
Solution
题意
给定一个正整数 \(n\),求正整数 \(x,y,z\) 满足 \(\frac{2}{n} = \frac{1}{x} + \frac{1}{y} + \frac{1}{z}\)。
其中 \(x \neq y,\ x \neq z,\ y \neq z\)。若无解输出 \(-1\)。
题解
构造
\(\frac{1}{n} - \frac{1}{n + 1} = \frac{1}{n(n+1)}\)
\(\frac{1}{n} = \frac{1}{n + 1} + \frac{1}{n(n+1)}\)
\(\frac{2}{n} = \frac{1}{n + 1} + \frac{1}{n(n+1)} + \frac{1}{n}\)
当 \(n=1\) 时,\(\frac{2}{n}=2\)。而 \((\frac{1}{x}+\frac{1}{y}+\frac{1}{z})_{max} = \frac{1}{1}+\frac{1}{2}+\frac{1}{3} < 2\),所以当 \(n=1\) 时无解。
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if(n == 1) cout << -1 << endl;
else cout << (n + 1) << " " << (n * (n + 1)) << " " << n << endl;
return 0;
}
Codeforces 743C - Vladik and fractions (构造)的更多相关文章
- CodeForces 743C Vladik and fractions (数论)
题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- CF C. Vladik and fractions——构造题
题目 构造一组 $x, y, z$,使得对于给定的 $n$,满足 $\frac{1}{x} + \frac{1}{y} + \frac{1}{z} = \frac{2}{n}$. 分析: 样例二已 ...
- codeforces 811E Vladik and Entertaining Flags(线段树+并查集)
codeforces 811E Vladik and Entertaining Flags 题面 \(n*m(1<=n<=10, 1<=m<=1e5)\)的棋盘,每个格子有一个 ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...
- 【44.64%】【codeforces 743C】Vladik and fractions
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Educational Codeforces Round 10 B. z-sort 构造
B. z-sort 题目连接: http://www.codeforces.com/contest/652/problem/B Description A student of z-school fo ...
- Codeforces 707C Pythagorean Triples(构造三条边都为整数的直角三角形)
题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外 ...
- Codeforces 1246D/1225F Tree Factory (构造)
题目链接 https://codeforces.com/contest/1246/problem/D 题解 首先考虑答案的下界是\(n-1-dep\) (\(dep\)为树的深度,即任何点到根的最大边 ...
随机推荐
- 能打开电脑都看懂的系列之Windows下修改MongoDB用户密码
起因 还能怎么滴,我忘了MongoDB的密码呗. 操作 进入MongoDB的安装目录的bin目录下,(我的目录是D:\developer\MongoDB\Server\4.2\bin): 用记事本打开 ...
- 77、tensorflow手写识别基础版本
''' Created on 2017年4月20日 @author: weizhen ''' #手写识别 from tensorflow.examples.tutorials.mnist import ...
- ubuntu 18.04 自启动
按下面二种方式打开自启动设置窗口,设置启动参数:(两种方式) 方式一:在桌面左上角的搜索框中输入Startup Applications,打开,点击Add,Name处填open_terminal(自定 ...
- laravel生成key
安装laravel之后要设置一个随即字符串作为应用密钥(key),如果你是通过composer或者laravel安装器安装的 这个key已经自动生成并设置了. 一般情况下这个key为32位长度字符串. ...
- 弹出框中的AJAX分页
$(function() { $("body").on("click",".set-topic",function(){ /*获取所有题目接 ...
- java入门经验分享——记面向对象先导课程学习感想
选择在暑期学习面向对象先导课程的初衷是为大二下学期面向对象课程做一些铺垫,接触入门java语言.在接触java的过程中,就编程语言的学习方法而言,我从刚入学时的手慌脚乱四处寻求帮助到现在慢慢养成了自己 ...
- #include和前置声明(forward declaration)
#include和前置声明(forward declaration) 1. 当不需要调用类的实现时,包括constructor,copy constructor,assignment opera ...
- JVM(1):Java 类的加载机制
原文出处: 纯洁的微笑 java类的加载机制 1.什么是类的加载 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个java.lang. ...
- 使用LoadRunner监控Apache
前提本文使用的是lampp环境下自带的Apache服务 一.查看文件 查看文件确保目录中有Apache,我在这里使用的是用xampp自带apache [root@besttest ~]# ll 二.配 ...
- python基础【第五篇】
python第三节 1.整型及布尔值 1.1 进制转换 十进制 ----二进制 二进制 ----十进制 8421方法与普通计算 python中十进制转二进制示例:bin(51)>>> ...