A Mathematical Curiosity
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30722 Accepted Submission(s): 9845
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.
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
Source
Recommend
好了!各位Oier大家好,又到了每天一水的时间......超级水果的题,注意格式就行!
好吧,解释一下题意:
给2个整数n和m,计算关于整数式子(a,b)(就是定义一种新的运算方式).a和b满足(0<a<b<n)并且(a^2+b^2+m)/(a*b)要是一个整数,要求上面的式子要整除(a*b),这个问题包含多组测试数据!
第一行的测试输入是整数N,然后就是N组测试数据,然后空行之后跟着就是N组输入块,每一组输入块之后要空一行,
例如每一组如下
输入n,m;只要n!=0&&m!=0就一直读入n和m的值,输出答案,然后n=0并且m=0时候这组数据算结束,结束得输出一个空行,最后一组不要输出空行,然后这题就没有坑点了!!
就是类似这种:
3
10 1
2 5
3 3
6 8
0 0
2 9
3 7
0 0
6 6
5 4
9 8
0 0
10 1
2 5
3 3
6 8
0 0
2 9
3 7
0 0
6 6
5 4
9 8
0 0
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int i = 0;
int t = input.nextInt();
for (i = 0; i < t; i++)
{
int cas = 1;
while (true)
{
int n = input.nextInt();
int m = input.nextInt();
int ans = 0;
if (n == 0 && m == 0)
break;
for (int a = 1; a < n; a++)
{
for (int b = a + 1; b < n; b++)
{
if ((a * a + b * b + m) % (a * b) == 0)
{
ans++;
}
}
}
System.out.println("Case " + cas + ": " + ans);
cas++;
}
if (i != t - 1)
{
System.out.println();
}
}
}
}