[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}$. 分析: 样例二已 ...
随机推荐
- 解决Jackson2反序列化LocalDateTime报错
今天在整合redis和spring boot的时候,遇到了一个错误,记录一下. 报错如下: Could not read JSON: Cannot construct instance of `jav ...
- [Jupyter Notebook] 01 这么多快捷键,我可顶不住!先记个八成吧
0. 一些说明 为了入门 Python3 安装了 Anaconda,它集成了 Jupyter Notebook 1. 调出快捷键表 打开 Jupyter Notebook,新建一个 Python3(我 ...
- P1190排队接水
这是2010年普及组第二题(话说我怎么只做普及组的题?因为太蒻). 这道题可以用搜索或者模拟来做,果断编了几组例子去分析来模拟,利用了贪心的思想得出:每次比较每个水龙头的空闲时间点,谁早就放到谁那里, ...
- HDU 5266 pog loves szh III ( LCA + SegTree||RMQ )
pog loves szh III Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- Runnable、Callable和Future三者对比
Runnable是个借口,使用简单: 1. 实现该接口并重写run方法 2. 利用该类的对象创建线程 3. 线程启动时就会自动调用该对象的run方法 通常在开发中结合ExecutorServi ...
- Spring基础18——通过注解配置bean之间的关联关系
1.组件装配 <context:component-scan>元素还会自动注册AutowiredAnnotaionBeanPostProcessor实例,这是一个bean的后置处理器,该实 ...
- MySQL 5.7原生通用二进制格式安装包安装过程
目录 官方文档 文件说明 官方文档 https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html 文件说明 Directory Co ...
- 分页控件SSTab
一.分页控件SSTab概述1.作用:采用分页形式查询或编辑数据表中数据.2.添加到控件箱菜单命令:工程 | 部件,选择:Microsoft Tabbed Dialog Control 6.0 (SP6 ...
- web框架-(一)初识web框架
一.web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:ut ...
- 使用glew和glad 新建窗口
一.添加头文件 首先,将头文件加到项目的.cpp文件中 #include <glad/glad.h> 2 #include <GLFW/glfw3.h> 注: 包含glad的头 ...