文章目录
1017、A Mathematical Curiosity
Given two integers n and m, count the number of pairs of integers (a,b) such that 0 < a < b < n and (a2+b2 +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
Code:
1、判断一个数double类型的数是否为整数,可以使用fmod(a,1)函数,若其结果为0,则其为整数
2、判断int类型的a和b,a/b是否为整数,可以判断a%b==0
3、注意输出的格式要求
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int N,m,n,count;
while(cin>>N){
//cout<<endl;
for(int j=0;j<N;j++){
int i=0;
while(cin>>n>>m){
if(n==0&&m==0) break;
double a,b,result;
count=0;
for(b=n-1;b>0;b--){
for(a=b-1;a>0;a--){
result=(pow(a,2)+pow(b,2)+m)/(a*b);
if(fmod(result,1)==0)
count++;
}
}
i++;