当前位置:网站首页>【代码源】每日一题 分数拆分
【代码源】每日一题 分数拆分
2022-07-25 09:20:00 【self_disc】
题目链接:分数拆分 - 题目 - Daimayuan Online Judge
题目描述:
输入正整数 k,找到所有的正整数 y≤x, 使得 1/k=1/x+1/y。
输入格式
输入一个正整数 k(1≤k≤10^7)。
输出格式
输出一个数,表示满足条件的x,y的个数。
样例输入
12样例输出
8因为k的范围很大对应x,y可能取值也会很大,如果暴力枚举无疑会超时,那么我们考虑缩小下枚举的范围。
给出了k,x,y之间的关系,k已知,对x,y我们已知一项便可以通过等式推到另一项。再根据y<=x,可以得到y<=2k,并且y>k。由等式可以得到x=(ky)/(y-k)。
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt, k, ans;
int main()
{
cin >> k;
for (ll y = k + 1; y <= k + k; y++)
{
if ((k * y) % (y - k) == 0)
ans++;
}
cout << ans;
}边栏推荐
- SSM框架整合,简单案例
- Two Sum
- Numpy- array属性、改变形状函数、基本运算
- 基本的网络知识
- *6-2 CCF 2015-03-3 节日
- idea中将lib目录下的jar包加入到项目中
- jsPDF生成PDF文件,文件不全问题,后台进行文件下载,前台不下载
- What are stand-alone, cluster and distributed?
- Guangzhou has carried out in-depth "100 day action" to check the safety of self built commercial houses, and more than 2 million houses have been checked in two months
- 在Ubuntu中安装MySQL并创建新用户
猜你喜欢

What are stand-alone, cluster and distributed?

¥1-3 SWUST oj 942: 逆置顺序表

~4.1 剑指 Offer 05. 替换空格

『每日一问』简单聊聊JMM/说说对JMM的了解

How can technologists start their personal brand? Exclusive teaching of top five KOLs

~4.2 ccf 2021-12-1 序列查询

*7-1 CCF 2015-09-1 数列分段

sqli-labs Basic Challenges Less1-10

Publish Yum private server using nexus3 (offline intranet)

~5 ccf 2021-12-2 序列查询新解
随机推荐
How can technologists start their personal brand? Exclusive teaching of top five KOLs
[GKCTF 2021]easynode
idea 热部署
excl批量导入数据,后台公共解析方法
The interviewer asked: how to prevent oversold? There are several ways to achieve it
OverTheWire-Natas
¥1-2 例2.2 将两个集合的并集放到线性表中
通过robocopy对文件/夹进行复制
sqli-labs Basic Challenges Less1-10
C#语言和SQL Server数据库技术
Read and write mongodb database files
MySQL的索引、视图与事务
~4.2 ccf 2021-12-1 序列查询
~5 ccf 2021-12-2 序列查询新解
~4.1 剑指 Offer 05. 替换空格
C#语言和SQL Server数据库技术
变量名可以用中文?直接把人干蒙了
C#语言和SQL Server数据库技术
实现简单的RESTful API服务器
¥1-3 SWUST oj 942: 逆置顺序表