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\n",count);
        for(int i=1;i<=count;i++){
        printf("1/%d = 1/%d + 1/%d\n",k,pairs[i].x,pairs[i].y);
        }        
    }
    return 0;
}
复制代码

 

posted on   SijingLin  阅读(155)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示