Description
给出两个整数n和m,找到满足(a^2+b^2 +m)/(ab) 是正整数的所有有序对(a,b)的对数(0 < a < b < n)
Input
第一行为大用例组数T,每组大用例分多组小用例,每组小用例占一行包括两个整数n和m,以0 0结束一组大用例的输入
Output
对于每组用例,输出满足条件的有序对(a,b)的对数
Sample Input
1
10 1
20 3
30 4
0 0
Sample Output
Case 1: 2
Case 2: 4
Case 3: 5
Solution
水题,暴力枚举a,b即可,注意输出的格式
Code
#include<cstdio>
#include<iostream>
using namespace std;
int count(int n,int m)
{
int sum=0;
for(int a=1;a<n;a++)
for(int b=a+1;b<n;b++)
if(!((a*a+b*b+m)%(a*b)))
sum++;
return sum;
}
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int res=1;
int n,m;
while(scanf("%d%d",&n,&m)&&(n||m))
{
int ans=count(n,m);
printf("Case %d: %d\n",res++,ans);
}
if(N)
printf("\n");
}
return 0;
}