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

Source

East Central North America 1999, Practice
题目分析:题意是说,第一行输入一个数N,分N模块进行输入输出,在模块中输入一组(n,m),使它们同时满足0 < a < b < n和 (a^2+b^2 +m)/(ab)是整数的解的个数。
注意:模块之间的输入输出要有一个空行,还有输入时逻辑运算的应用。


#include<iostream>
using namespace std;
int main()
{
int a,b,m,n,num,i,s,N;
cin>>N;
for(i=0;i<N;i++)
{
s=1;
while(cin>>n>>m,n||m)
{
num=0;
for(a=1;a<n;a++)
{
for(b=a+1;b<n;b++)
{
if((a*a+b*b+m)%(a*b)==0)
num++;
}
}
cout<<"Case "<<s<<": "<<num<<endl;
s++;
}
if(i!=N-1)
cout<<endl; //至关重要,各模块间有一行是空行。
}
return 0;
}

程序运行如下:





杭电OJ_DIY_YTW2_1001 A Mathematical Curiosity的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  3. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  4. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  5. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  6. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  7. A Mathematical Curiosity 分类: HDU 2015-06-25 21:27 11人阅读 评论(0) 收藏

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

  8. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  9. 杭电ACM2092--整数解

    杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...

随机推荐

  1. 计算闰年_winform

    新建窗体应用程序(如下),新建控件label1,label2,label3,textBOX1,button1,button2 label1的Text属性改为“计算闰年演示” label2的Text属性 ...

  2. ECSHOP常用函数

    lib_time.php gmtime() #获得当前格林威治时间的时间戳 /$0 server_timezone() #获得服务器的时区 /$0 local_mktime($hour = NULL ...

  3. 一种用javascript实现的比较兼容的回到顶部demo + 阻止事件冒泡

    回到页面顶部demo <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. 树莓派安装ftp服务器

    在树莓派安装ftp服务器,可上载\下载文件 vsftpd是开源的轻量级的常用ftp服务器. 1,安装vsftpd服务器 (约400KB)sudo apt-get install vsftpd 2,启动 ...

  5. iOS 将UIColor转换为UIImage

    /** * 将UIColor变换为UIImage * **/+ (UIImage *)createImageWithColor:(UIColor *)color{ CGRect rect = CGRe ...

  6. 数据库中操作XML(openXML)

    最近公司项目需要在数据库中操作XML,因此系统的学习了一下 一.openxml的格式 OPENXML( idoc int [ in] , XPathnvarchar [ in ] , [ flags ...

  7. Android自定义组合控件:UIScrollLayout(支持界面滑动及左右菜单滑动)

    一.前言: 我之前很早的时候,写过一篇<左右滑出菜单>的文章: http://blog.csdn.net/qingye_love/article/details/8776650 用的是对V ...

  8. Oracle 11gR2的完全卸载

    首先停止oracle服务,卸载oracle,其次删除oracle文件夹,最后删除oracle服务和清理注册表. 以下是详细教程 1.关闭oracle所有的服务.可以在windows的服务管理器中关闭: ...

  9. 转:onConfigurationChanged的作用

    API原文说明:android:configChangesLists configuration changes that the activity will handle itself. When ...

  10. 基于visual Studio2013解决C语言竞赛题之0614递归大元素

     题目 解决代码及点评 /************************************************************************/ /* 14. 编一个程 ...