A Mathematical Curiosity
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40381 Accepted Submission(s): 12967
Problem Description
Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a^2+b^2 +m)/(ab) is an integer.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
You will be given a number of cases in the input. Each case is specified by a line containing the integers n and m. The end of input is indicated by a case in which n = m = 0. You may assume that 0 < n <= 100.
Output
For each case, print the case number as well as the number of pairs (a,b) satisfying the given property. Print the output for each case on one line in the format as shown below.
Sample Input
1 10 1 20 3 30 4 0 0
Sample Output
Case 1: 2 Case 2: 4 Case 3: 5
/*
* 水题,主要是处理输出格式
* 输出格式要求:N个输入块对应着N个输出块,两个输出块之间有一个空白行
* 需要注意的是:如果某一个输入块为只有(0 0)一个数据,输出块不作任何输出(包括空白行)
* 其次,同一个输出块中的输出没有空白行,每个输出块的case计数都从1开始
*/
//
// Created by Admin on 2017/3/28.
//
#include <cstdio>
int main(){
int t,rec=0,mark=0; //rec用于处理第一个输出块的情况
//mark用于跟踪某输出块一定存在输出(即不是输入块只有(0 0)的情况)
scanf("%d",&t);
while (t--){
int n,m,flag=1,count=0;
while(scanf("%d%d",&n,&m)){
if(n==0&&m==0)break;
int ans=0;
for (int a = 1; a < n-1; ++a) {
for (int b = a+1; b < n ; ++b) {
if ((a*a+b*b+m)%(a*b)==0)ans++;
}
}
if(rec&&flag){ //如果前面已有输出块,且本次输出为该输出块的第一个输出
printf("\nCase %d: %d\n",++count,ans); //在输出的前面加空白行
flag=0; //不是该输出块的第一个输出不加空白行
}
else {
printf("Case %d: %d\n",++count,ans);
mark=1; //必有输出块
}
}
rec=mark; //如果有输出块,rec置1
}
return 0;
}