http://acm.hdu.edu.cn/showproblem.php?pid=1017枚举,a:2--->n-2,b:a+1...n-1;验证(a,b):(a*a+b*b+m)%(a*b)即可!!!
水题一个,注意输出格式:
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int N,n,m,a,b,i,t,ans,flag=0;
scanf("%d",&N);
for (i=1;i<=N ;i++ )
{
if (flag)
printf("\n");
flag=1;t=0;
while (scanf("%d%d",&n,&m)&&(n!=0)||(m!=0))
{
t++;
ans=0;
for (a=1;a<n ;a++ )
for (b=a+1;b<n ;b++ )
{
if ((a*a+b*b+m)%(a*b)==0)
{
ans++;
}
}
printf("Case %d: %d\n",t,ans);
}
}
return 0;
}
做做水题,练习输入输出格式还是有用的。呵呵,