航电OJ1017

看似很难,实际暴力计算就可以AC

需要注意题目描述的输出形式

分为N块,每一块内有任意组数据构成,当读入n=0,m=0时,跳出该块,并且块与块间要空一行。输出内容为“Case x: y”

Problem Description

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

内容大意:

给定两个整数n和m,计算整数对(a,b)的数量,以使0 <a <b <n和(a ^ 2 + b ^ 2 + m)/(ab)是整数。

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

多个输入的第一行是整数N,然后是空白行,后跟N个输入块。每个输入块均采用问题描述中指示的格式。输入块之间有一个空白行。

输出格式由N个输出块组成。输出块之间有一条空白行。
输入项
输入中将提供许多案例。每种情况由包含整数n和m的行指定。输入的结尾由n = m = 0的情况表示。您可以假设0 <n <= 100。
输出量
对于每种情况,打印情况编号以及满足给定属性的对数(a,b)。如下所示,将每种情况的输出打印在一行上。

附上AC代码
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int N;
    scanf("%d",&N);
    while(N--){
        int i=1;
        while(i){
            int n,m;
            scanf("%d %d",&n,&m);
            int sum=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)
                        sum++;
            printf("Case %d: %d\n",i,sum);
            i++;
        }
        if(N)
            printf("\n");
    }
    return 0;
}

发布了5 篇原创文章 · 获赞 14 · 访问量 607

猜你喜欢

转载自blog.csdn.net/qq_43732324/article/details/103207956