A Mathematical CuriosityTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 48317 Accepted Submission(s): 15520 http://acm.hdu.edu.cn/showproblem.php?pid=1017 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. 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,m。当n=0时,此输入块结束。输出满足(a^2+b^2 +m)/(ab)的(a,b)种数(0 < a < b < n)。
题目很简单,就是原题说n=m=0时输出结束,但这个题只有n=0时输出结束才对。ayixi~~
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
int N;
cin>>N;
while(N--)
{
int n,m;
int h=1;
while(cin>>n>>m&&n!=0)
{
int sum=0;
for(int b=2;b<n;b++)
{
for(int a=1;a<b;a++)
{
if((a*a+b*b+m)%(a*b)==0)
sum++;
}
}
cout<<"Case "<<h++<<": "<<sum<<endl;
}
if(N!=0)
cout<<endl;
}
return 0;
}