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

  1. /*对于英语如我这样的人来说,,,,题目是天书啊。看了别人的翻译才知道什么意思的。。。
  2. 大概意思是:(0 < a < b < n ) (a^2+b^2 +m)/(ab) 的结果是一个整数,
  3. 所以满足需要(a^2+b^2 +m)%(ab)等于0。
  4. 输出:求这样的(a,b)有多少对。
  5. 懂了意思就是个水题。
  6. 还有注意输出格式:
  7. 第一个输入t为有t组数据。
  8. 每组数据有n,m2个数。
  9. 当n==0&&m==0时,这一组的输入结束,进行下一组。
  10. 每2组之间的输出有一个空行。
  11. */
  12. import java.util.Scanner;
  13. public class Main{
  14. public static void main(String[] args) {
  15. Scanner sc = new Scanner(System.in);
  16. int t = sc.nextInt();
  17. while(t-->0){
  18. int p = 0;
  19. while(sc.hasNext()){
  20. int n = sc.nextInt();
  21. int m = sc.nextInt();
  22. int num=0;
  23. if(n==0&&m==0){
  24. break;
  25. }
  26. for(int a=1;a<n-1;a++){
  27. for(int b=a+1;b<n;b++){
  28. if((a*a+b*b+m)%(a*b)==0){
  29. num++;
  30. }
  31. }
  32. }
  33. System.out.println("Case "+(++p)+": "+num);
  34. }
  35. if(t!=0)
  36. System.out.println();
  37. }
  38. }
  39. }

HDOJ 1017 A Mathematical Curiosity的更多相关文章

  1. HDU 1017 A Mathematical Curiosity【水,坑】

    A Mathematical Curiosity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  2. HDU 1017 A Mathematical Curiosity (数学)

    A Mathematical Curiosity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  3. HDU 1017 A Mathematical Curiosity【看懂题意+穷举法】

    //2014.10.17    01:19 //题意: //先输入一个数N,然后分块输入,每块输入每次2个数,n,m,直到n,m同一时候为零时  //结束,当a和b满足题目要求时那么这对a和b就是一组 ...

  4. Hdu oj 1017 A Mathematical Curiosity

    题目:pid=1017">点击打开链接 #include<stdio.h> int main() { int t; scanf("%d",&t) ...

  5. HDU 1017 - A Mathematical Curiosity

    题目简单,格式酸爽.. #include <iostream> using namespace std; int ans,n,m,p; int main() { cin>>p; ...

  6. HDU 1017 A Mathematical Curiosity(枚举)

    题目链接 Problem Description Given two integers n and m, count the number of pairs of integers (a,b) suc ...

  7. HDU 1017 A Mathematical Curiosity 数学题

    解题报告:输入两个数,n和m,求两个数a和b满足0<a<b<n,并且(a^2+b^2+m) % (a*b) =0,这样的a和b一共有多少对.注意这里的b<n,并不可以等于n. ...

  8. HDU 1017 A Mathematical Curiosity (输出格式,穷举)

    #include<stdio.h> int main() { int N; int n,m; int a,b; int cas; scanf("%d",&N); ...

  9. HDU 1017 A Mathematical Curiosity (枚举水题)

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

随机推荐

  1. Electron

    跨平台桌面app开发 Appjs hex nwjs electron 官网:http://electron.atom.io/ 中文文档:https://github.com/atom/electron ...

  2. java编程思想-泛型思维导图

  3. Android之使用json进行网络数据交换

    JSON作为一种轻量级的数据交换格式,凭借其易于阅读和编写.易于解析.传输速度快等优点流行了起来.最近正好在学习Android端从服务端端取数据,Json便派上了用场.好,下面开始切入主题. 1.准备 ...

  4. [转]最详细的 HTTPS 科普扫盲帖

    转载自http://www.codeceo.com/article/https-knowledge.html 为什么需要https HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都 ...

  5. 【转】Auto Layout 进阶

    原文:http://blog.csdn.net/ysy441088327/article/details/12558097   引言: Auto Layout是iOS6发布后引入的一个全新的布局特性, ...

  6. XML约束图解

  7. 日期Calendar/Date的用法

    package cn.jason.datas; import java.util.Date;import java.text.ParseException;import java.text.Simpl ...

  8. 设置Imindmap默认字体

    创建一个新的字体样式 根据如下步骤创建新的字体样式: 1.打开一个mindmap,选中工具栏上的 [样式][Styles ]. 2.选择 Font > Create New Font Optio ...

  9. c/c++内存机制(一)(转)

    转自:http://www.cnblogs.com/ComputerG/archive/2012/02/01/2334898.html 一:C语言中的内存机制 在C语言中,内存主要分为如下5个存储区: ...

  10. 事件的委托处理(Event Delegation)

    javascript的事件模型,采用”冒泡”模式,也就是说,子元素的事件会逐级向上”冒泡”,成为父元素的事件. 利用这一点,可以大大简化事件的绑定.比如,有一个表格(table元素),里面有100个格 ...