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& ...
随机推荐
- 二次战CPP链表
Felling By Ruiy: Pre-learnning link list knowloages 熟悉 指针相关操作应用+结构体数据类型应用,且能简单融合使用,堆内存(内存泄露)->类似于 ...
- JavaScript之作用域与作用域链
今天是2016的第一天,我们得扬帆起航踏上新的征程了.此篇阐述JavaScript中很重要的几个概念:作用域与作用域链及相关知识点. 我们先从变量与作用域的行为关系开始讨论. 变量作用域 JavaSc ...
- bootstrap 仿实例
bootstrap实现一个网页 html文件 <!DOCTYPE html> <html> <head lang="en"> <meta ...
- PHP安全编程:跨站脚本攻击的防御(转)
跨站脚本攻击是众所周知的攻击方式之一.所有平台上的Web应用都深受其扰,PHP应用也不例外. 所有有输入的应用都面临着风险.Webmail,论坛,留言本,甚至是Blog.事实上,大多数Web应用提供输 ...
- php session_set_save_handler 函数的用法(mysql)(转)
<?php /*============================文件说明======================================== @filename: s ...
- 尚未解决的intellij问题:补充措施
2016-12-06 遇到问题 D:\software\apache-tomcat-7.0.57\bin\catalina.bat run [2016-12-06 09:54:52,342] Arti ...
- Android WindowManager的使用
经常,我们看到在桌面上可移动的悬浮窗,这种场景还是很多的, 像流量统计,桌面歌词等,安全软件的清理小部件 这种小部件主要是通过 WindowManager ; WindowManager.Layout ...
- uva 1391 Astronauts(2-SAT)
/*翻译好题意 n个变量 不超过m*2句话*/ #include<iostream> #include<cstdio> #include<cstring> #inc ...
- c#将Excel数据导入到数据库的实现代码(OleDb)
sing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web ...
- 关于mtk Android打开串口权限问题
最近在做一个测试串口读写回路的APK,jni代码部分遇到一个小小问题: fd = open(path_utf, O_RDWR);返回值是-1,要么就是权限问题,要么就是文件不存在所以需要打印错误信息, ...