当前位置:网站首页>【代码源】每日一题 分数拆分
【代码源】每日一题 分数拆分
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;
}边栏推荐
- How can technologists start their personal brand? Exclusive teaching of top five KOLs
- Two Sum
- C language and SQL Server database technology
- ActiveMQ -- dead letter queue
- sqli-labs Basic Challenges Less11-22
- @Scheduled源码解析
- 『每日一问』ReentrantLock加锁解锁
- Go基础4
- Mongodb installation and use
- Activemq-- asynchronous delivery
猜你喜欢

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

Activemq-- delayed delivery and scheduled delivery

将list集合的某一字段拼接单个String

分布式一致性协议之Raft

『怎么用』装饰者模式

~1 ccf 2022-06-2 寻宝!大冒险!

¥1-1 SWUST oj 941: 有序顺序表的合并操作的实现
![[GKCTF 2021]easynode](/img/f0/1daf6f83fea66fdefd55608cbddac6.png)
[GKCTF 2021]easynode

~4.1 剑指 Offer 05. 替换空格

@2-1 CCF 2020-12-01 期末预测之安全指数
随机推荐
[GYCTF2020]Ez_Express
将list集合的某一字段拼接单个String
[De1CTF 2019]SSRF Me
Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground
实现简单的RESTful API服务器
有误差的字符串型时间比较方法String.compareTo
Nacos搭建配置中心出现client error: invalid param. endpoint is blank
What is the difference between mongodb and redis
Thymeleaf 笔记
基本的网络知识
matplotlib数据可视化三分钟入门,半小时入魔?
『每日一问』怎么实现一个正确的双重检查锁定
Analysis of five data structure principles of redis
PHP介绍
MySQL排序
API健康状态自检
数据分析之numpy基础包
uni-app如何获取位置信息(经纬度)
CentOS changes MySQL database directory
&lt;T&gt;泛型方法演示