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 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>
#include <cstdio>
using namespace std;
int xx[],yy[];
int main()
{
int k,x,y,total; while(cin >> k && k!=)
{
total = ;
for(int i=k+; i<=*k; i++)
{
if(k*i%(i-k)==)
{
xx[total] = k*i/(i-k);
yy[total] = i;
total++;
}
}
cout<<total<<endl;
for(int i=; i<total; i++)
{
printf("1/%d = 1/%d + 1/%d\n",k,xx[i],yy[i]);
}
}
return ;
}
uva 10976 Fractions Again(简单枚举)的更多相关文章
- 暴力枚举 UVA 10976 Fractions Again?!
题目传送门 /* x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k */ #include <cstdio> #inc ...
- UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】
[题意]:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对. [分析]:枚举所有在区间[k+1, 2k]上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解. [ ...
- uva 10976 fractions again(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3gAAAM+CAIAAAB31EfqAAAgAElEQVR4nOzdO7KtPJum69GEpAcVQQ ...
- Uva 10976 Fractions Again?!
直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace s ...
- UVA 725 UVA 10976 简单枚举
UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...
- UVA - 10167 - Birthday Cake (简单枚举)
思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include &l ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- UVA.10986 Fractions Again (经典暴力)
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
随机推荐
- 浅谈JavaScript函数
JavaScript作为一种基于对象(非严格面向对象)的语言,函数在JS中的地位非同一般:用函数声明类和对象.甚至函数本身也是对象. 一.函数的三种声明方式辨析. 1.function命令 funct ...
- VMware: windows8 与 虚拟机ubuntu 14.04 共享文件夹
假设当前用户为xxx 安装 VMwareTools 1. 打开 VMwareworkstation窗口,选择”虚拟机” -> “重新安装VMwareTools(T)”. 点击之后,会发现 Ubu ...
- Struts2学习笔记(三):result配置的各项视图转发类型
Struts 1: <action path="/user" type="org.sunny.user.action.UserAction" ...> ...
- Swift_UILabel
一.初始化 // 初始化UIlabel,并设置frame //let labelOne = UILabel.init(frame: CGRect.init(x: 10, y: 20, width: 3 ...
- mysql主从复制 详解
转自 http://blog.csdn.net/m582445672/article/details/7731565 实践: http://shiyanjun.cn/archives/584.html ...
- 深入理解javascript闭包(一)
闭包(closure)是Javascript语言的一个难点.也是它的特色,非常多高级应用都要依靠闭包实现. 一.什么是闭包? 官方"的解释是:闭包是一个拥有很多变量和绑定了这些变量的环境的表 ...
- [置顶] iOS 名片识别代码
采用的是惠普图片识别SDK.本代码可以识别中文.代码改自 http://www.cocoachina.com/bbs/read.php?tid=123463 . 图片就不贴了,123463中的效果是可 ...
- [React Flow] Up and Running with Facebook Flow for Typed JavaScript
Install: npm i -D flow-binnpm i -g flow-bin Init: flow init Script: "typecheck": "flo ...
- [AngularJS] Enable Animations Explicitly For A Performance Boost In AngularJS
http://www.bennadel.com/blog/2935-enable-animations-explicitly-for-a-performance-boost-in-angularjs. ...
- codevs 1128 导弹拦截 (贪心)
/* 题目大体意思是两套系统好多导弹 怎样分配使得两个系统所拦截的最大半径之和最小 贪心:把距离1系统最远的 让2拦截 记好距离 然后按照距离1由远到近排序 对于每一个导弹 如果这之前的都给2拦截 则 ...