UVA 10976(暴力)
UVA 10976
题意:输入正整数k,找到所有的正整数x>=y,使得1/k=1/x+1/y。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
ll a, b, c;
};
ll n, cnt;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
while(~scanf("%lld", &n)){
cnt = 0;
vector<node> Q;
for(ll i = n + 1; i <= 2 * n; i++){
ll t = n * i;
if(t % (i - n) == 0){
Q.push_back((node){n, t / (i - n), i});
cnt++;
}
}
printf("%d\n", cnt);
for(int i = 0; i < Q.size(); i++){
printf("1/%d = 1/%d + 1/%d\n", Q[i].a, Q[i].b, Q[i].c);
}
}
return 0;
}
本文介绍了一种解决UVA10976题目的算法,该题目要求对于给定的正整数k,找出所有满足1/k=1/x+1/y条件的正整数对(x,y),其中x>=y。通过使用暴力搜索的方法,文章提供了一个C++实现的代码示例,有效地解决了这个问题。
179

被折叠的 条评论
为什么被折叠?



