UVA10976Fractions Again?!(暴力解法)

本文探讨了对于形式为1/k的任意分数,如何找到所有符合条件的正整数x和y (x≥y),使得1/k = 1/x + 1/y成立的方法。通过给出具体的程序代码实现,详细介绍了寻找这些整数对的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续暴力
先分析,xy关系可以推算出y的最大范围2k
解:x>=y 即1/x<=1/y 由于1/x=1/k - 1/y 代入得1/k<=2/y 即y<=2k
然后枚举y即可求出x,再判断。
It is easy to see that for every fraction in the form 1/k(k>0), we can always nd two positive integersxandy, 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

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
    int x,y,k,s;
    while(scanf("%d", &k)!=EOF)
    {
        s=0;
        for(y=k+1; y<=2*k; y++){
            if((k*y)%(y-k)==0){
                x=(k*y)/(y-k);
                if(x>=y) s++;
            }
        }
        printf("%d\n", s);
        for(y=k+1; y<=2*k; y++){
            if((k*y)%(y-k)==0){
                x=(k*y)/(y-k);
                if(x>=y) printf("1/%d = 1/%d + 1/%d\n", k, x, y);
            }
        }
    }
    return 0;
}

要改注意全改啊。。。别只改一处啊。。。笨蛋。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值