[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}$. 分析: 样例二已 ...
随机推荐
- Mysql函数----控制流函数介绍
MySQL有4个函数用来进行条件操作的,可以实现SQL的条件逻辑,允许开发者将一些应用程序业务逻辑转换到数据库后台. MySQL控制流函数: 1.CASE WHEN[test1] THEN [re ...
- CentOS7 策略路由配置
环境说明:Cloud1中的GE0/0/1.GE0/0/3.GE0/0/5接口,分别与Centos7中的eth1.eth2.eth3接口桥接到同一虚拟网卡,R1,R2,R3均配置一条静态默认路由指向Ce ...
- 《剑指offer》面试题23 从上往下打印二叉树 Java版
注意层序遍历的时候对每一层的处理方式可能不同,这里把每一层的元素保存进一个List中了,那么就需要记录每一层的数量. public List<List<Integer>> se ...
- [BZOJ4569] [Luogu 3295] [SCOI2016]萌萌哒(并查集+倍增)
[BZOJ4569] [Luogu 3295] [SCOI2016]萌萌哒(并查集+倍增) 题面 有一个n位的十进制数a(无前导0),给出m条限制,每条限制\((l_1,r_1,l_2,r_2)(保证 ...
- CSS 毛玻璃效果
效果图: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <met ...
- hdu1465不easy系列之中的一个(错排)
版权声明:本文为博主原创文章,未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/37512659 转载请注明出 ...
- 如何将一个.NET Core类库发布到NuGet
包治百病 | 如何将一个.NET Core类库发布到NuGet 写文章 包治百病 | 如何将一个.NET Core类库发布到NuGet Edi Wang发表于汪宇杰博客订阅 77 NuGet是.NET ...
- 轮播图--js课程
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 使用阿里ARouter路由实现组件化(模块化)开发流程
Android平台中对页面.服务提供路由功能的中间件,我的目标是 —— 简单且够用. 这是阿里对Arouter的定位,那么我们一起来梳理一下Arouter使用流程,和使用中我所遇到的一些问题! 先来看 ...
- NSPredicate的使用,超级强大
NSPredicate *ca = [NSPredicate predicateWithFormat:(NSString *), ...]; Format: (1)比较运算符>,<,==, ...