Fractions Again?! UVA - 10976

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/88357752
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct Node
{
    int x,y;
    Node(int i,int j):x(i),y(j) {}
    Node() {}
};

vector<Node>ans;

int main()
{
    int k;
    int flag;
    int sum = 0;
    double temp = 0;
    while(cin>>k&&k)
    {
        flag = 1;
        ans.clear();
        for(int y = k+1; y<=2*k&&flag; y++)
        {
            temp = k*y*1.0/(y-k);
            if(temp==(int)temp)
            {
                ans.push_back(Node(temp,y));

            }
        }
        cout<<ans.size()<<endl;
        for(int i = 0; i<ans.size(); i++)
            printf("1/%d = 1/%d + 1/%d\n",k,ans[i].x,ans[i].y);
    }


    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/88357752