【题意】:给你一个数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?!【暴力枚举/注意推导下/分子分母分开保存】的更多相关文章

  1. 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 ...

  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.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

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

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

  5. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  6. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  7. 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 ...

  8. Uva 10976 Fractions Again?!

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

  9. UVA.10986 Fractions Again (经典暴力)

    UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...

随机推荐

  1. A1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  2. [jzoj5233]概率博弈(树形DP)

    Description 小A和小B在玩游戏.这个游戏是这样的: 有一棵

  3. unity安装记录

    官网直接下载(http://unity3d.com/cn/) 下载完后,会要求输入账号密码.我是先在官网进行一个账号注册,然后登陆即可. 首先会要你输入一个已有的邮箱,进行认证.进入自己邮箱,点击链接 ...

  4. 不同storyboard间跳转

    小项目中用到storyboard,可以按照模块来新建多个sb. 以下是代码实现跳转实现: UIStoryboard *anSb=[UIStoryboard storyboardWithName:@&q ...

  5. 【Reverse Integer】cpp

    题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click ...

  6. 【Combination Sum II 】cpp

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  7. 并发编程——多进程——multiprocessing开启进程的方式及其属性(3)

    开启进程的两种方式——Process 方式一:函数方法 from multiprocessing import Process import time def task(name): print('% ...

  8. 从shell(终端)中退出python

    从shell(终端)中退出python: 1.输入命令行:$ exit() 2.快捷键: ctrl+Z

  9. Kafka SSL 配置

    #!/bin/bash # 生成服务器keystore(密钥和证书)keytool -keystore server.keystore.jks -alias machine03.zheng.com - ...

  10. [luogu_P1251][LOJ#6008]「网络流 24 题」餐巾计划

    [luogu_P1251][LOJ#6008]「网络流 24 题」餐巾计划 试题描述 一个餐厅在相继的 \(N\) 天里,第 \(i\) 天需要 \(R_i\) 块餐巾 \((i=l,2,-,N)\) ...