A Mathematical Curiosity
题意大致为:Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a2+b2+m)/(ab) is an integer.
利用循环和判断可以解决,关键在于输出的格式,组间要换行,而最后一组不换行。
#include<stdio.h>
main(){
int N,n,m,i,count,a,b;
scanf("%d",&N);
while(N--){
i=0;
while(scanf("%d %d",&n,&m)!=EOF){
count=0;
if(!n&&!m)
break;
i++;
for(a=1;a<n-1;a++){
for(b=a+1;b<n;b++)
if((a*a+b*b+m)%(a*b)==0)
count++;
}
printf("Case %d: %d\n",i,count);
}
if(N!=0)
printf("\n");
}
}