HDOJ 1017 A Mathematical Curiosity

简介: HDOJ 1017 A Mathematical Curiosity

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

/*对于英语如我这样的人来说,,,,题目是天书啊。看了别人的翻译才知道什么意思的。。。
大概意思是:(0 < a < b < n ) (a^2+b^2 +m)/(ab) 的结果是一个整数,
所以满足需要(a^2+b^2 +m)%(ab)等于0。
输出:求这样的(a,b)有多少对。
懂了意思就是个水题。
还有注意输出格式:
第一个输入t为有t组数据。
每组数据有n,m2个数。
当n==0&&m==0时,这一组的输入结束,进行下一组。
每2组之间的输出有一个空行。
*/
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int p = 0;
            while(sc.hasNext()){
                int n = sc.nextInt();
                int m = sc.nextInt();
                int num=0;
                if(n==0&&m==0){
                    break;
                }
                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){
                            num++;
                        }
                    }
                }
                System.out.println("Case "+(++p)+": "+num);
            }
            if(t!=0)
                System.out.println();
        }
    }
}
目录
相关文章
|
JSON JavaScript 搜索推荐
Github 精选 #4 | 让 Github 帮你自动压缩图片!
Github 精选 #4 | 让 Github 帮你自动压缩图片!
Github 精选 #4 | 让 Github 帮你自动压缩图片!
|
弹性计算 运维 安全
带你读《云上自动化运维宝典》——万字长文带你了解 CloudOps自动化运维的奥秘,助力云上业务高效稳定运行(1)
带你读《云上自动化运维宝典》——万字长文带你了解 CloudOps自动化运维的奥秘,助力云上业务高效稳定运行(1)
731 1
|
安全 Java 程序员
Java 8 中 ReentrantLock 与 Synchronized 的区别
Java 8 中 ReentrantLock 与 Synchronized 的区别
|
机器学习/深度学习 编解码 数据可视化
【unity本站最全系列】unity常用API大全一篇文章足以(万字详解)不信你不收藏
【unity本站最全系列】unity常用API大全一篇文章足以(万字详解)不信你不收藏
3058 1
|
算法 数据可视化 数据处理
MATLAB内置函数
【10月更文挑战第6天】本文详细介绍了MATLAB的内置函数和自定义函数,涵盖数学计算、矩阵操作、图形绘制等方面。通过具体代码示例,展示了如何使用内置函数和创建自定义函数,以及它们在性能、灵活性和可读性上的优劣。同时,文章还讨论了函数文件与脚本文件的区别,匿名函数和函数句柄的高级应用,帮助读者更好地利用MATLAB解决复杂问题。
|
存储 安全 NoSQL
Cookie、Session、Token 解析
Cookie、Session、Token 解析
958 1
|
设计模式 Java API
设计模式-------------静态/动态代理模式(结构型设计模式)
本文详细介绍了代理模式,包括其定义、应用场景、UML类图、代码实现和实际例子,阐述了静态代理和动态代理的区别以及它们的优缺点,展示了如何通过代理模式来控制对目标对象的访问并增强其功能。
|
图形学
【制作100个unity游戏之27】使用unity复刻经典游戏《植物大战僵尸》,制作属于自己的植物大战僵尸随机版和杂交版5(附带项目源码)
【制作100个unity游戏之27】使用unity复刻经典游戏《植物大战僵尸》,制作属于自己的植物大战僵尸随机版和杂交版5(附带项目源码)
591 0
DFA与NFA的区别,由正规表达式构造DFA,以及DFA的相关化简
DFA与NFA的区别,由正规表达式构造DFA,以及DFA的相关化简
2297 1
DFA与NFA的区别,由正规表达式构造DFA,以及DFA的相关化简
|
Linux 虚拟化
此虚拟机的处理器所支持的功能不同于保存虚拟机状态的虚拟机的处理器所支持的功能
此虚拟机的处理器所支持的功能不同于保存虚拟机状态的虚拟机的处理器所支持的功能
3572 0
此虚拟机的处理器所支持的功能不同于保存虚拟机状态的虚拟机的处理器所支持的功能

热门文章

最新文章