UVA.10986 Fractions Again (经典暴力)
题意分析
同样只枚举1个,根据条件算出另外一个。
代码总览
#include <iostream>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define nmax 200
#define eps 1e-6
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n) != EOF){
//double sta = 1.0/n;
queue<int> a,b;
for(int i = n+1; i<= 2* n; ++i){
int ak = ( n * i) / (i - n);
if(ak * i == n * (ak + i)){
a.push(ak);
b.push(i);
}
}
printf("%d\n",a.size());
while(!a.empty()){
int x = a.front();a.pop();
int y = b.front();b.pop();
printf("1/%d = 1/%d + 1/%d\n",n,x,y);
}
}
return 0;
}