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. 模拟Hibernate框架的小demo

    该程序为尚学堂马士兵老师讲解,模拟了hibernate的原理,主要应用了字符串拼接,反射知识. step1,新建数据库 use jd; create table _student( _id int(1 ...

  2. C#_会员管理系统:开发四(日志查看)

    新建一个日志查看窗体: 日志需要的登录时间和登录状态信息由用户刚登录程序时就提供,所以在登录窗体(VIPLogin.cs)中添加代码: //定义一个全局变量 Uid; //用于获取登录成功后的用户名 ...

  3. [转]Windows7 64bit下配置Apache+PHP+MySQL

    原文链接:http://blog.csdn.net/sbz0409/article/details/12946375 1.准备资料: 首先下载文件:Apache2.4.16 64bit,http:// ...

  4. django 新闻编辑笔记

    url(r'^news_manage/edit/$',views.news_edit,name='edit') url配置 <a href="/management/news_mana ...

  5. Triangle---minimum path sum

    动态规划 class Solution: # @param triangle, a list of lists of integers # @return an integer def minimum ...

  6. svn:怎样批量删除.svn文件

    怎样批量删除.svn文件 使用SVN工具的时候会生成一些以“svn”作为后缀的文件,而且每个文件夹下都有,如果想删除这些.svn文件夹,通过手动删除的渠道是很繁琐的事情. 通过以下的简单步骤可以在右键 ...

  7. 基于visual Studio2013解决C语言竞赛题之0708字符串查找

       题目

  8. 给你的Cordova HybridApp加入Splash启动页面

    如今最新的Cordova 3以上的版本号支持启动画面了,是通过cordova插件实现的. 眼下Splash插件支持android,ios,blackberry等多个平台. 加入插件等步骤例如以下: 加 ...

  9. tab group of firefox

    https://addons.mozilla.org/en-US/firefox/addon/tabgroups-menu/? src=search#detail-relnotes https://g ...

  10. 浅谈PPM (Project Portfolio Management) - 1

    前言: 本文以纯理论性的PPM解说为主,不会涉及到具体怎样实施,我会在以后介绍具体的PPM实施方案介绍. PPM,可能非常多人并不清楚甚至可能没听说过,这是一个近些年才流行起来的概念,是Project ...