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. metasploit使用

    新版本的Metasploit分为Pro和Communicate版本,都可以使用WebUI的方式和Console的方式 下面主要介绍console方式的使用 1.   use

  2. android View层的绘制流程

    还记得前面<Android应用setContentView与LayoutInflater加载解析机制源码分析>这篇文章吗?我们有分析到Activity中界面加载显示的基本流程原理,记不记得 ...

  3. Counting Bloom Filter

    Counting Bloom Filter是 改进型,将记录标准的存在位0和1,扩展为计数器counter.记录有几个元素.插入加一,删除减一.多占几倍存储空间. 标准的Bloom Filter是一种 ...

  4. UML之部署图

    部署图,英文名曰:Deployment Diagram,通常也称配置图,她是用来显示系统中软件和硬件的物理结构,从部署图中,我们可以了解到软件和硬件组件之间的物理关系以及处理节点的组件分布情况,使用部 ...

  5. Make3D Convert your image into 3d model

    Compiling and Running Make3D on your own computer source: http://make3d.cs.cornell.edu/code_linux.ht ...

  6. Tomcat configuration DataSource

    1. configuration MySql Connection DataSource 原理介绍 java 调用 Tomcat 中的 ConnectionPool 通过Context 中去查找  j ...

  7. Gradle 1.12用户指南翻译——第三十七章. OSGi 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  8. Gridview的item含有checkbox,setOnItemClickListener方法失效的问题

    在开发中我们常常遇到一些莫名奇妙的问题,就比如Gridview的item含有checkbox,setOnItemClickListener方法失效的问题. 刚开始网上搜了一下,如http://my.o ...

  9. Junit指定测试执行顺序

    原文链接: Test execution order原文日期: 2012年12月06日翻译日期: 2014年7月2日翻译人员: 铁锚说明: Junit4.11版本及以后才支持,建议升级到最新版本.按照 ...

  10. shell脚本里面相互调用时路径不要用pwd获取

    shellA调用shellB,如果shellB 里面需要使用路径作为变量,去寻找其它文件.那么要注意,不用pwd,其返回的是系统中用户当前所在位置的路径,也就是shellA的路径,这样就错了.应该用d ...