NYOJ 66 分数拆分

原题链接

关键点是通分后判断分子分母能否整除

附ac代码:

#include <stdio.h>

int main(){
	int t, k, x, y, tempa, tempb;
	scanf("%d", &t);
	while(t-- && scanf("%d", &k)){
		for(y = k + 1; y <= 2 * k; ++y){
			tempa = y - k;
			tempb = y * k;
			if(tempb % tempa == 0){				
				x = tempb / tempa;
				if(x >= y) 
					printf("1/%d=1/%d+1/%d\n", k, x, y);
			}
		}
	}
	return 0;
}


posted on 2014-02-11 17:24  长木Qiu  阅读(142)  评论(0编辑  收藏  举报