[codeforces743C]:Vladik and fractions(数学)
题目传送门
题目描述
请找出一组合法解使得$\frac{1}{x}+\frac{1}{y}+\frac{1}{z}=\frac{2}{n}$成立。
其中$x,y,z$为正整数且互不相同。
输入格式
一个整数$n$。
输出格式
一组合法的解$x,y,z$,用空格隔开。
若不存在合法的解,输出“-1”。
样例
样例输入
2
样例输出
2 3 6
数据范围与提示
对于$100%$的数据满足$n\leqslant {10}^4$
要求答案中$x,y,z\leqslant 2\times {10}^9$
提供$Special Judge$
题解
如果你看到了这里,说明你比我还菜。
毕竟我样例都给你了……
找规律也该找出来了……
你可定会$\Theta(n^3)$的暴力。
稍加思考会发现可以根据$x,y$推出$z$,$\Theta(n^2)$就出来了。
但是数据范围显然是让我们$\Theta(1)$(虽说原题$n\leqslant {10}^4$)。
你真的菜,读到这里还想不到$\Theta(1)$。。。
好吧,那我就告诉你,毕竟我发现了比我还菜的人……
有这样一个式子:$\frac{1}{n}-\frac{1}{n+1}=\frac{1}{n\times (n+1)}$。
那么我们移个项:$\frac{1}{n\times (n+1)}+\frac{1}{n+1}-\frac{1}{n}=0$。
两边同时加$\frac{2}{n}$:$\frac{1}{n}+\frac{1}{n+1}+\frac{1}{n\times (n+1)}=\frac{2}{n}$。
那么我们让$x=n,y=n+1,z=n\times (n+1)$就好啦……
看到这里,是不是觉得自己是智障?
停!!!
不要轻生!!!
笔者概不负责!!!
代码时刻
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
scanf("%lld",&n);
if(n==1||n==0)puts("-1");
else printf("%lld %lld %lld",n,n+1,n*n+n);
return 0;
}
rp++
[codeforces743C]:Vladik and fractions(数学)的更多相关文章
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- Codeforces 743C - Vladik and fractions (构造)
Codeforces Round #384 (Div. 2) 题目链接:Vladik and fractions Vladik and Chloe decided to determine who o ...
- 数学【CF743C】Vladik and fractions
Description 请找出一组合法的解使得\(\frac {1}{x} + \frac{1}{y} + \frac {1}{z} = \frac {2}{n}\)成立 其中\(x,y,z\)为正整 ...
- 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 ...
- vjudge I - Vladik and fractions 一道小学生的提。
原题链接:https://vjudge.net/contest/331993#problem/I Vladik and Chloe decided to determine who of them i ...
- CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
- CodeForces 743C Vladik and fractions (数论)
题意:给定n,求三个不同的数满足,2/n = 1/x + 1/y + 1/z. 析:首先1是没有解的,然后其他解都可以这样来表示 1/n, 1/(n+1), 1/(n*(n+1)),这三个解. 代码如 ...
- CF C. Vladik and fractions——构造题
题目 构造一组 $x, y, z$,使得对于给定的 $n$,满足 $\frac{1}{x} + \frac{1}{y} + \frac{1}{z} = \frac{2}{n}$. 分析: 样例二已 ...
随机推荐
- eclipse maven 项目突然所有的JS方法都失效了
原因:JS 或者 jQuery 有严重的语法错误
- unsigned char bcd串乱码问题解决
unsigned char bcd[13]; ...... string bcdstr; for(int i=0;i < 12;i++) { bcdstr=FormatString(" ...
- 手写一个IOC容器
链接:https://pan.baidu.com/s/1MhKJYamBY1ejjjhz3BKoWQ 提取码:e8on 明白什么是IOC容器: IOC(Inversion of Control,控制反 ...
- Python web 面试题(一)
1.列举django的内置组件? url .view.model.template.中间件 2.列举django中间件的5个方法?以及django中间件的应用场景? process_request(s ...
- 获取kafka最新offset-java
之前笔者曾经写过通过scala的方式获取kafka最新的offset 但是大多数的情况我们需要使用java的方式进行获取最新offset scala的方式可以参考: http://www.cnblog ...
- SQL Server之索引解析(一)
SQL Server之索引解析(一) 1.写在前面 微软专门给出SQL Server设计思路及实现路线,从7大体系结构阐述是如何实现,通过了解这些,我们就可以总结出数据库设计原则.编程中sql写法 ...
- @-webkit-keyframes 动画 css3
Internet Explorer 10.Firefox 以及 Opera 支持 @keyframes 规则和 animation 属性. Chrome 和 Safari 需要前缀 -webkit-. ...
- windows和linux安装rabbitmq
一.windows安装rabbitmq 1.安装erlang 点击进入官网下载:http://erlang.org/download/ 2.安装rabbitmq 点击进入官网下载:http://www ...
- luogu P5337 [TJOI2019]甲苯先生的字符串
传送门 所以这题和字符串有什么关系 首先可以写出dp,\(f_{i,j}\)表示前\(i\)位,最后一个字符是\(j\)的方案,转移枚举下一位,只要不在大串中前后相邻即可.然后矩乘优化即可 // lu ...
- Linux下RabbitMQ安装、运行与管理
Linux下RabbitMQ安装.运行与管理 安装erlang 安装参考官网 RabbitMQ的安装需要Erlang的基础环境,必须按照RabbitMQ Erlang版本要求进行安装. 关于Erlan ...