UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】
【题意】:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对。
【分析】:枚举所有在区间【k+1, 2k】上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解。
【代码】:
#include<bits/stdc++.h>
using namespace std;
int x[10005];
int y[10005];
#define LL long long int main()
{
int k,c;
while(~scanf("%d",&k))
{
c=0;
for(int Y=k+1 ;Y<=k<<1; Y++)
{
if((Y*k) % (Y-k)==0)//y是整数
{
x[c]=(Y*k)/(Y-k);
y[c]=Y;
c++;
}
}
printf("%d\n",c);
for(int i=0; i<c; i++)
{
printf("1/%d = 1/%d + 1/%d\n",k,x[i],y[i]);
}
} }
UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】的更多相关文章
- 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 ...
- 暴力枚举 UVA 10976 Fractions Again?!
题目传送门 /* x>=y, 1/x <= 1/y, 因此1/k - 1/y <= 1/y, 即y <= 2*k */ #include <cstdio> #inc ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- uva 10976 fractions again(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3gAAAM+CAIAAAB31EfqAAAgAElEQVR4nOzdO7KtPJum69GEpAcVQQ ...
- Uva 10167 - Birthday Cake 暴力枚举 随机
Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- UVa 10603 Fill [暴力枚举、路径搜索]
10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...
- Uva 10976 Fractions Again?!
直接暴力 没技巧 y应该从k+1开始循环,因为不然y-k<0的时候 你相当于(x*y) % (负数) 了. #include <iostream> using namespace s ...
- UVA.10986 Fractions Again (经典暴力)
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...
随机推荐
- A1065 A+B and C (64bit) (20)(20 分)
A1065 A+B and C (64bit) (20)(20 分) Given three integers A, B and C in [-2^63^, 2^63^], you are suppo ...
- Codeforces Round #462 (Div. 2) D. A Determined Cleanup
D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...
- js数据类型的检测总结,附面试题--封装一个函数,输入任意,输出他的类型
一.javascript 中有几种类型的值 1.基本数据类型 : 包括 Undefined.Null.Boolean.Number.String.Symbol (ES6 新增,表示独一无二的值) 特点 ...
- Sql获取数据表字段说明
SELECT Sysobjects.name AS TABLE_NAME , syscolumns.Id , syscolumns.name AS COLUMN_NAME , systypes.nam ...
- Linux之如何进行固定IP、DNS等设置
前提:虚拟机Linux centOS6.6 Linux如何设置固定IP.dns.网关 1.切换到root账号 2.#cd /etc/sysconfig/network-scripts 进入网卡的设置 ...
- hnust 聚宝盆
问题 A: 聚宝盆 时间限制: 1 Sec 内存限制: 128 MB提交: 663 解决: 282[提交][状态][讨论版] 题目描述 Grace是个善良的同学,他经常帮助同学解决问题.这天,他正 ...
- 精通CSS高级Web标准解决方案(7、布局)
7.1 让设计居中 7.1.1 使用自动空白边让设计居中 <body> <div id="wrapper"> </div> </body& ...
- apple键盘中的Tilde / back-tick key can't work
使用波浪键的时候会输出>或<. 解决办法:http://atodorov.org/blog/2015/04/30/fixing-tilde-and-function-keys-mappin ...
- linux VIM编辑器常用指令
一般模式 查看文本-移动光标 [Ctrl] + [f] 屏幕『向前』移动一页 [Ctrl] + [b] 屏幕『向后』移动一页 n<space> 按下数字后再按空格键,光标会向右移动这一 ...
- POJ-2159 最小费用最大流
Going Home 自己写的第一道费用流,图建好一波板子AC.不过还是有几个地方有点迷. 先来 ...