UVA 10976 Fractions Again?! 简单枚举题

#include<stdio.h>
struct pairs{
    int x,y;
};
struct pairs pairs[10000];

int judge(int k,int i){
    if((k*i)%(i-k)==0)
    return 1;
    else
    return 0;
}

int main(){
    int k,count;
    while(scanf("%d",&k)!=EOF){
       count=0;
       for(int i=k+1;i<=2*k;i++){
          if(judge(k,i)){
            count++;      
            pairs[count].x=k*i/(i-k);
            pairs[count].y=i;
            }
        }
    
        printf("%d
",count);
        for(int i=1;i<=count;i++){
        printf("1/%d = 1/%d + 1/%d
",k,pairs[i].x,pairs[i].y);
        }        
    }
    return 0;
}
原文地址:https://www.cnblogs.com/lsj2020/p/5793243.html