A Mathematical Curiosity

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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
 
题解:给定一个N,表示有N组测试数据。每组测试数据中每次给定n 和 m。当n = m = 0时结束本组测试数据。得到n 和m 之后,需要计算令(a ^ 2 + b ^ 2 + m) / (ab) 为整数的a, b的组数。。a, b满足(0 < a < b < n)。(注意格式问题,容易出现PE)
 
代码:
#include<iostream>
using namespace std;
int n,m,sum,t,k;
int main()
{
cin>>t;
while(t--)
{
k=;
while(cin>>n>>m)
{
if(n==&&m==)
break;
sum=;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
int temp=i*i+j*j+m;
int flag=i*j;
if(temp%flag==) //测试为整数
sum++;
}
cout<<"Case"<<" "<<++k<<": "<<sum<<endl;
}
if(t!=)
cout<<endl; //不是最后一行就需要空格
}
return ;
}

HDU-1017的更多相关文章

  1. HDU 1017 直接暴力。

    C - 3 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  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

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

  4. HDU 1017 A Mathematical Curiosity(枚举)

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

  5. HDU 1017(** **)

    题意是给定 n,m,问有多少组(a,b)满足 0 < a < b < n 而且 (a ^ 2 + b ^ 2 + m) / ( a * b ) 是整数. 直接模拟即可. 代码如下: ...

  6. 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. ...

  7. HDU 1017 A Mathematical Curiosity (数学)

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

  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 ...

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

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

随机推荐

  1. Android学习之Animation(三)

    今天观看了一个关于android动画的一些知识,就顺便记录下来,以备之后的学习和参考. 在XML文件中使用LayoutAnimationController 第一步: 在res/anim文件夹下创建一 ...

  2. Cocos2D:塔防游戏制作之旅(十二)

    以上代码块相当直观 - 但是它分解的有些细致了. 首先,敌人通过传递HelloWorldLayer对象的引用而初始化.在init方法里,少数重要的变量被设置: maxHP:定义敌人有多经打(Tough ...

  3. JAVA内部类_2

    (d)匿名内部类 如果只创建这个类的第一个对象,就无需命名. 由于构造器的名字必须与类名相同,而匿名类没有类名,所以匿名类没有构造器. 取而代之的是将构造器参数传递给超类构造器. 在内部类实现接口的时 ...

  4. Mybatis接口编程原理分析(三)

    前面两篇博客Mybatis接口编程原理分析(一)和Mybatis接口编程原理分析(二)我们介绍了MapperProxyFactory.MapperProxy和MapperMethod的操作及源码分析, ...

  5. 工作中常用的Linux命令

    1.从其他机器拷贝文件夹 格式: scp -r 文件夹名 用户名@机器名:/路径 范例: scp -rsearch work@zjm-testing-ps23.zjm.baidu.com:/home/ ...

  6. 过时api LocalActivityManager 作用

    换了个新工作,看公司代码还在用LocalActivityManager类 不知道是个什么东西,百度了也没具体介绍查了下sdk是这样介绍的 LocalActivityManager是一个助手类,在同一个 ...

  7. 开放源码的安卓天气应用-android学习之旅(73)

    我在github上面发布了简易的天气应用,能够简单显示全国各个省市县市的天气 效果图片如下 源代码我放在github上了.我希望大家可以去下载,修改以后在上传维护,我的代码很简单.算是抛砖引玉,希望大 ...

  8. Notepad++ 使用探索

    一.更换主题,视觉享受 1,http://wiki.macromates.com/Themes/UserSubmittedThemes,从网站上下载自己喜欢的主题,解压 2,复制Black Pearl ...

  9. 【Java编程】Eclipse快捷键

    Alt+左箭头,右箭头        以在编辑窗口切换标签 Alt+上下箭头,                以自动选择鼠标所在行,并将其上下移动 Ctrl+f6                    ...

  10. ffdshow 源代码分析 8: 视频解码器类(TvideoCodecDec)

    ===================================================== ffdshow源代码分析系列文章列表: ffdshow 源代码分析 1: 整体结构 ffds ...