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;
}
做做水題,練習輸入輸出格式還是有用的。呵呵,