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\)为树的深度,即任何点到根的最大边 ...
随机推荐
- 68、Schema的相关类
public class SObjectSchema { public void testSchema(){ //获取SObject的token //1.先获取所有token,然后通过key获取需要的 ...
- Git 设置和取消代理(SOCKS5代理)
设置代理 git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'socks ...
- how to convert from hex to disasm
cat ascii.hex | ascii2binary -b h -t us > ascii.bin x86dis -e 0 -s att -f ascii.bin echo "d8 ...
- python *arg和**kwargs的区别
转载自:https://www.cnblogs.com/yunguoxiaoqiao/p/7626992.html 一.*args的使用方法 *args 用来将参数打包成tuple给函数体调用 举个栗 ...
- gitlab+gitlab-ci+docker自动化部署
导言 本次测试用的是gitlab-ci,单纯与gitlab搭配而言,gitlab-ci较jenkins更加一体,顺畅. 主机1:192.168.100.151 gitlab 主机2:192.168.1 ...
- 微信小程序 获取用户信息并保存登录状态
微信小程序 获取用户信息并保存登录状态:http://www.360doc.com/content/18/0124/11/9200790_724662071.shtml
- 开发效率优化之自动化构建系统Gradle(二)下篇
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从自定义 Gradle 插件开发来介绍自动化构建系统 ...
- docker--image的获取
image有几种获取方式: 1.Docker官方提供了一种文件格式:Dockerfile,通过这种格式的文件,我们可以定义一个image,然后通过Dockerfile我们可以构建(build)一个im ...
- Rabbitmq的延时队列的使用
配置: spring: rabbitmq: addresses: connection-timeout: username: guest password: guest publisher-confi ...
- fixture实战---通过fixure,解决方法依赖逻辑
import pytest@pytest.fixture()def login(): print('输入用户名密码登陆') def test_cart(login): print('用例1,登陆后执行 ...