【HDOJ】【1017】A Mathematical Curiosity

来源:互联网 发布:java开发的工作内容 编辑:程序博客网 时间:2024/06/06 05:53

被格式坑得飞起,看了好久好久才通过。

代码显得比较low,还可以继续进行优化。


#include <stdio.h>#include <stdlib.h>#include <string.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char *argv[]) {int N,n,m,CaseNum,a,b,count;float tmp;while(scanf("%d",&N)!=EOF){while(N--){CaseNum = 0;while(scanf("%d%d",&n,&m)!=EOF){if(n==0 && m==0)break;{count = 0;for(b = n-1;b>1;b--){for(a=1;a<b;a++){tmp = (float)(a*a+b*b+m)/(a*b);if((int)tmp == tmp){count++;}}}printf("Case %d: %d\n",++CaseNum,count);}}if(N)printf("\n");}}system("PAUSE");return 0;}


0 0
原创粉丝点击