It is easy to see that for every fraction in the form 1
k
(k > 0), we can always find two positive integers
x and y, x ≥ y, such that:
1
k
=
1
x
+
1
y
Now our question is: can you write a program that counts how many such pairs of x and y there
are for any given k?
Input
Input contains no more than 100 lines, each giving a value of k (0 < k ≤ 10000).
Output
For each k, output the number of corresponding (x, y) pairs, followed by a sorted list of the values of
x and y, as shown in the sample output.
Sample Input
2
12
Sample Output
2
1/2 = 1/6 + 1/3
1/2 = 1/4 + 1/4
8
1/12 = 1/156 + 1/13
1/12 = 1/84 + 1/14
1/12 = 1/60 + 1/15
1/12 = 1/48 + 1/16
1/12 = 1/36 + 1/18
1/12 = 1/30 + 1/20
1/12 = 1/28 + 1/21
1/12 = 1/24 + 1/24

#include <iostream>//求1/n = 1/x + 1/y
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int x[],y[];
int main()
{
int n,cnt;
while(cin >> n)
{
memset(x,,sizeof(x));
memset(y,,sizeof(y));
cnt = ;
for(int i=n+;i<=*n;i++)
{
if((i*n)%(i-n)==)//注意这个判断条件,判断等式是否可能成立
{
x[cnt] = (i*n)/(i-n);//求x的式子
y[cnt] = i;
cnt++;
}
}
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
printf("1/%d = 1/%d + 1/%d\n",n,x[i],y[i]);
}
return ;
}

最新文章

  1. Enterprise Architect 学习 之 活动图
  2. 从零开始学iPhone开发(3)——视图及控制器的使用
  3. 基于MVC4+EasyUI的Web开发框架形成之旅--基类控制器CRUD的操作
  4. 日志log使用序列反序列加密(Serializer) DESCrypto 加密
  5. 查看windows系统热键占用情况
  6. C# 索引器 学习
  7. Camera图像处理原理及实例分析-重要图像概念
  8. 获取手机root的方法
  9. linux内核源码结构
  10. POJ1328 Radar Installation(贪心)
  11. 利用内存结构及多线程优化多图片下载(IOS篇)
  12. 必学100个常用linux命令大全
  13. jstl标签经典
  14. error while loading shared libraries: libmcrypt.so.4
  15. C# .NET Socket 简单实用框架
  16. C# 4动态编程新特性与DLR剖析
  17. hdu3183 RMQ
  18. python之路——22
  19. 使用sklearn估计器构建K-Means聚类模型
  20. 测试系统工程师TSE的职责与培养

热门文章

  1. maven添加oracle驱动包
  2. ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
  3. 使用verilog编写锁存器与触发器
  4. 整理用Java实现数字转化成字符串左边自动补零方法
  5. x32下PsSetLoadImageNotifyRoutine的逆向
  6. 挂起(suspend)与线程阻塞工具类LockSupport
  7. 6.源码分析---和dubbo相比SOFARPC是如何实现负载均衡的?
  8. Go中的字符串使用----strings和strconv
  9. 从Maven私服获取依赖
  10. MyEclipse下安装FreeMark插件