当前位置: 代码迷 >> 综合 >> A Mathematical Curiosity数学好奇心 15
  详细解决方案

A Mathematical Curiosity数学好奇心 15

热度:86   发布时间:2023-12-12 05:34:01.0

AMathematical Curiosity数学好奇心

Problem Description

Given two integersn 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 followedby N input blocks. Each input block is in the format indicated in the problemdescription. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line betweenoutput blocks.

 给定两个整数n和m,计数对整数数(A,B),使得0<A <B<n和(一个^ 2+ B^ 2+ M)/(AB)是一个整数。

这个问题包含多个测试用例!

一个多输入的第一行是一个整数N,则空白行随后N个输入块。每个输入块是在问题说明指示的格式。有输入块之间的空行。

输出格式包括N个输出模块。有输出块之间的空行。

 

Input

You will be givena number of cases in the input. Each case is specified by a line containing theintegers n and m. The end of input is indicated by a case in which n = m = 0.You may assume that 0 < n <= 100.

 您将得到一个数字输入的情况下。每一种情况下被含有整数n和m的线指定。输入的结束是由一个壳体表示其中n=米= 0你可以假设0<N <=100。

 

Output

For each case,print the case number as well as the number of pairs (a,b) satisfying the givenproperty. Print the output for each case on one line in the format as shownbelow.

 对于每一种情况下,打印的情况下数目以及对数(A,B)满足给定的属性。打印每个情况下,输出上的格式一行如下所示。

 

Sample Input

1

10 1

20 3

30 4

0 0

 

Sample Output

Case 1: 2

Case 2: 4

Case 3: 5


代码如下:

#include <stdio.h>
#include <stdlib.h>
///* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{int n, m, times, count = 0, i, j, flag = 1;scanf("%d", ×);while(times--){while(1){scanf("%d%d", &n, &m);if(!n && !m) break;for(i=1; i<n; ++i)for(j=1; j<i; ++j)if((i*i+j*j+m)%(i*j) == 0) count++;printf("Case %d: %d\n", flag++, count);count = 0;}flag = 1;if(times != 0) printf("\n");}return 0;
}