Fractions Again?!(简单枚举)
来源:互联网 发布:淘宝店铺新开0信誉排名 编辑:程序博客网 时间:2024/05/17 04:59
Fractions Again?!
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:.
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
212
Sample Output
21/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
/// 1/n = 1/x + 1/y ==> n*y + n*x = x*y;///y只需要从n+1枚举到2*n即可,此时x = n*y / (y-n);#include<stdio.h>#include<string.h>int main(){ int n,i,p,num; int a[10000],b[10000]; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); num=0; for(i=n+1; i<=n*2; i++) { if(n*i%(i-n))continue; p=n*i/(i-n); a[num]=p; b[num]=i; num++; } printf("%d\n",num); for(i=0; i<num; i++) printf("1/%d = 1/%d + 1/%d\n",n,a[i],b[i]); }}
阅读全文
0 0
- Fractions Again?!(简单枚举)
- Uva 10976 Fractions Again(简单枚举)
- UVa10976-Fractions Again?!(枚举)
- UVa 10976 Fractions Again 枚举
- UVa 10976----Fractions Again?!(枚举)
- UVa--10976 Fractions Again(枚举)
- uva 10976 Fractions Again? 枚举
- Fractions Again?!(暴力)
- (暴力枚举) UVa 10976 Fractions Again?!
- UVa - 10976 - Fractions Again?!(暴力求解枚举)
- Fractions Again?!
- Fractions Again?!
- VUa 10976 Fractions Again?! (枚举+暴力水题)
- UVa 10976:Fractions Again?!(水题)
- 分数拆分(Fractions Again?!,UVa 10976)
- Uva 10976 Fractions Again?! (技巧暴力)
- UVA 10976 - Fractions Again?!
- UVA 10976 - Fractions Again?!
- 运维之python篇------1.Python 环境搭建、环境变量配置、数据类型
- 【七】机器学习之路——训练集、测试集及如何划分
- 表白被拒怎门办?
- LeetCode 之 Pascal's Triangle II
- Hadoop集群安装配置教程_Hadoop2.6.0_Ubuntu/CentOS
- Fractions Again?!(简单枚举)
- [JZOJ3370]【NOI2012】美食节
- 【git 使用详解(2)】--安装
- I
- 实验4:栈和队列的基本操作实现及其应用
- LeetCoe.138 Copy List with Random Pointer
- [noip2015]运输计划
- 1.7_03:基因相关性
- c语言实现组合数