当前位置:网站首页>1163: 松哥的分数拆分(C语言)
1163: 松哥的分数拆分(C语言)
2022-07-24 16:26:00 【小小小Why】
Description
松哥寒假回家帮他的外甥女做寒假作业,有一道题目是这样的,有一个表达式1/k=1/x+1/y.
其中x>=y.松哥想知道对于已知的k,所有满足条件的表达式有哪些,请从小到大列出它们.
Input
多组测试数据。每组测试数据包含一个正整数k(k<=5000).
Output
对于每组测试数据输出所有的表达式,若表达式不存在,则输出-1.
Sample Input
Sample Output
#include <stdio.h>
int main()
{
int k,y,s;
while(~scanf("%d",&k)){
s=0;//记录是否存在
for(y=k+1;y<=2*k;y++){ //k*y/(y-k)就是x,((k*y)%(y-k))==0说明x是整数,合法
if(((k*y)%(y-k))==0) printf("1/%d=1/%d+1/%d\n",k,k*y/(y-k),y),s=1;
}
if(s==0) printf("-1\n");//不存在输出-1
}
return 0;
}边栏推荐
- 聊聊C指针
- Huawei Kirin 985 mass production in the third quarter: TSMC 7Nm EUV process, integrated 5g baseband!
- [leetcode] day102 spiral matrix II
- Causes and solutions of QT signal and slot connection failure
- Qt键盘事件(二)——长按按键反复触发event事件问题解决
- EventLoop event loop mechanism
- [LeetCode]巧用位运算
- 收益率在百分之六以上的理财产品,请说一下
- 图像label处理——json文件转化为png文件
- “天上天下,唯我独尊”——单例模式
猜你喜欢

如何在 PHP 中防止 XSS

如何防止跨站点脚本 (XSS) 攻击完整指南

Yolov6 trains its own data set

Servlet framework (servlet+jsp) + addition, deletion, modification and query + paging implemented by MySQL (function package student information entry, addition, deletion, modification and query of st

Using native JS to realize magnifying glass function

31 next spread

Parse string

Research on the efficiency of numpy array access

Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer

做完数据治理,质量依旧很差
随机推荐
About SQL data query statements
Telephone system rules
Ligerui table control grid changes the color of rows (cells) according to the content
【LOJ3247】「USACO 2020.1 Platinum」Non-Decreasing Subsequences(DP,分治)
Druid integration shardingsphere appears xxmapper Reasons and solutions of XML error reporting
Yolov6 trains its own data set
LaneATT
Creation and inheritance of JS class
.net review the old and know the new: [6] what is LINQ
图片浏览器?Qt也可以实现!
leetcode:162. 寻找峰值【二分寻找峰值】
Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer
Analysis of double pointer sliding window method and solution of leetcode related problems
详解 Apache Hudi Schema Evolution(模式演进)
How to deal with the start and end times in mybatics
Software recommendation - Mechanical Major
Jenkins cli command details
收益率在百分之六以上的理财产品,请说一下
Yolov3 trains its own data set
C# TCP客户端窗体应用程序异步接收方式