当前位置:网站首页>【代码源】每日一题 分数拆分
【代码源】每日一题 分数拆分
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;
}边栏推荐
- @3-2 CCF 2020-12-2 期末预测之最佳阈值
- MySQL的索引、视图与事务
- What is the difference between mongodb and redis
- Nacos搭建配置中心出现client error: invalid param. endpoint is blank
- *7-2 CCF 2015-09-2 日期计算
- Redis operation uses cursor instead of keys
- nacos2.1.0集群搭建
- Ranking of data results in MySQL
- 【Nacos】NacosClient在服务注册时做了什么
- Go foundation 4
猜你喜欢
随机推荐
C language and SQL Server database technology
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
Understand the execution process of try, catch and finally (including return) (the most detailed analysis of the whole network)
Analysis of concat and group in MySQL_ Use of concat
API健康状态自检
Interviewer: tell me the difference between redis and mongodb? [easy to understand]
Understand why we should rewrite the equals method and hashcode method at the same time + example analysis
『每日一问』ReentrantLock加锁解锁
将list集合的某一字段拼接单个String
有误差的字符串型时间比较方法String.compareTo
Week summary
SSM框架整合,简单案例
Go foundation 1
OverTheWire-Bandit
@2-1 CCF 2020-12-01 期末预测之安全指数
Dynamically add multiple tabs and initialize each tab page
office文件对应的Content-Type类型
分布式一致性协议之Raft
jsPDF生成PDF文件,文件不全问题,后台进行文件下载,前台不下载
Thymeleaf 笔记







![[De1CTF 2019]SSRF Me](/img/12/44c37cc713b49172a10579c9628c94.png)

