hdu1017 A Mathematical Curiosity

 

A Mathematical Curiosity

 

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40381    Accepted Submission(s): 12967

 

 

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.

 

 

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个输出块,两个输出块之间有一个空白行
 * 需要注意的是:如果某一个输入块为只有(0 0)一个数据,输出块不作任何输出(包括空白行)
 *     其次,同一个输出块中的输出没有空白行,每个输出块的case计数都从1开始

 */

 

 

 

 

//
// Created by Admin on 2017/3/28.
//

#include <cstdio>

int main(){
    int t,rec=0,mark=0;  //rec用于处理第一个输出块的情况
    //mark用于跟踪某输出块一定存在输出(即不是输入块只有(0 0)的情况)
    scanf("%d",&t);
    while (t--){
        int n,m,flag=1,count=0;
        while(scanf("%d%d",&n,&m)){
            if(n==0&&m==0)break;
            int ans=0;
            for (int a = 1; a < n-1; ++a) {
                for (int b = a+1; b < n ; ++b) {
                    if ((a*a+b*b+m)%(a*b)==0)ans++;
                }
            }
            if(rec&&flag){  //如果前面已有输出块,且本次输出为该输出块的第一个输出
                printf("\nCase %d: %d\n",++count,ans);  //在输出的前面加空白行
                flag=0; //不是该输出块的第一个输出不加空白行
            }
            else {
                printf("Case %d: %d\n",++count,ans);
                mark=1; //必有输出块
            }
        }
        rec=mark; //如果有输出块,rec置1
    }
    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值