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 ;
}

Fractions Again?! UVA - 10976的更多相关文章

  1. 分数拆分(Fractions Again?!, UVa 10976)

    题目链接:https://vjudge.net/problem/UVA-10976 It is easy to see that for every fraction in the form 1k(k ...

  2. 暴力枚举 UVA 10976 Fractions Again?!

    题目传送门 /* x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k */ #include <cstdio> #inc ...

  3. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  4. uva 10976 Fractions Again(简单枚举)

    10976 Fractions Again It is easy to see that for every fraction in the form 1 k (k > 0), we can a ...

  5. Uva 10976 Fractions Again?!

    直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace s ...

  6. uva 10976 fractions again(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3gAAAM+CAIAAAB31EfqAAAgAElEQVR4nOzdO7KtPJum69GEpAcVQQ ...

  7. 分数拆分( Fractions Again, UVA 10976)-ACM

    It is easy to see that for every fraction in the form  (k > 0), we can always find two positive i ...

  8. UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】

    [题意]:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对. [分析]:枚举所有在区间[k+1, 2k]上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解. [ ...

  9. 【例题 7-3 UVA - 10976】Fractions Again?!

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] x>=y => \(\frac{1}{x}<=\frac{1}{y}\) => \(\frac{1}{x}= ...

随机推荐

  1. redis分布式锁&队列应用

    分布式锁 setnx(set if not exists) 如果设值成功则证明上锁成功,然后再调用del指令释放. // 这里的冒号:就是一个普通的字符,没特别含义,它可以是任意其它字符,不要误解 & ...

  2. WPF中如何禁用空格键(或其他键)

    在选择的控件中添加KeyDown event method private void OnKeyDown(object sender, KeyEventArgs e){ if (e.Key == Ke ...

  3. 夯实Java基础(六)——包装类

    1.包装类简介 我们都知道Java是面向对象编程语言,包含了8种基本数据类型,但是这8种基本数据类型并不支持面向对象的特征,它们既不是类,也不能调用方法.这在实际使用时存在很多的不便,比如int类型需 ...

  4. 最基础的 ant build 脚本

    最基础的 ant build 脚本,根据项目,自行进行修改 <?xml version="1.0" encoding="UTF-8" ?> < ...

  5. ThreadLocal为什么会内存泄漏

    1.首先看下ThreadLocal的原理图: 在ThreadLocal的生命周期中,都存在这些引用. 其中,实线代表强引用,虚线代表弱引用: 2.ThreadLocal的实现:每个Thread维护一个 ...

  6. Linux--shell的基本特性--01

    1.bash的基本特性: a) 命令展开:date命令—— 基于date命令创建命令 查看系统时钟:date 查看硬件时钟: clock .hwclock (常常同步系统时钟与硬件时钟) cal 查看 ...

  7. 对平底锅和垃圾的O奖论文的整理和学习[1](2018-02-08发布于知乎)

    今天和杉杉同志在Pacific Coffee坐了0.4天,目前两人都处于放空状态. 这种天气有暖气真的太棒了. 我今天看的论文是这两篇: MCM2013B题O奖论文MCM2016B题O奖论文 先说第一 ...

  8. Java请求Http

    一.工具类,直接粘贴调用即可 package cn.com.service.httpReq; import java.io.BufferedReader;import java.io.IOExcept ...

  9. R-package XML 安装失败及解决方式

    安装R-package XML遇到的问题和解决方式 这个问题已经困扰了我很久很久一直找不到解决之法,后来终于找到了! Fedora 27, R 3.5.0, libxml和libxml2以及开发包均已 ...

  10. 关于python中str数据类型的内置常用方法(函数)总结

    str基本数据类型常用功能 center(self,width,fllchar=none)                        内容居中,width表示总长度,fllchar表示空白处默认为 ...