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. iOS中 自定义cell升级版 (高级)

    接上次分享的自定义cell进行了优化:http://blog.csdn.net/qq_31810357/article/details/49611255 指定根视图: self.window.root ...

  2. Linux Debugging(七): 使用反汇编理解动态库函数调用方式GOT/PLT

    本文主要讲解动态库函数的地址是如何在运行时被定位的.首先介绍一下PIC和Relocatable的动态库的区别.然后讲解一下GOT和PLT的理论知识.GOT是Global Offset Table,是保 ...

  3. android的Drawable详解

    Drawable简介 Drawable有很多种,用来表示一种图像的概念,但他们又不完全是图像,他们是用过颜色构建出来的各种图像的表现形式.Drawable一般都是通过xml来定义的 ,当然我们也可以通 ...

  4. java常用集合类详解(有例子,集合类糊涂的来看!)

    Framework集合框架是一个统一的架构,用来表示和操作集合.集合框架主要是由接口,抽象类和实现类构成.接口:蓝色:实现类:红色Collection|_____Set(HashSet)|       ...

  5. 【翻译】了解Ext JS 5的小部件

    原文:Understanding Widgets in Ext JS 5 在Ext JS 5,引入了新的"widgetcolumn",支持在网格的单元格中放置组件.同时,还在Ext ...

  6. html详解(二)

    4.多媒体标签 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  7. 获取request参数的工具类

    package cn.edu.hactcm.util; import java.io.File; import java.io.FileOutputStream; import java.io.IOE ...

  8. Android官方技术文档翻译——Gradle 插件用户指南(4)

    最近赶项目,白天基本没时间,只有晚上在家的时候才能看一看.昨天晚上只翻译完了第四章,今天就只发第四章吧. 本文译自Android官方技术文档<Gradle Plugin User Guide&g ...

  9. [WinForm]动态显示本地目录图片与悬浮窗

    加载显示: if (File.Exists(@"D:\产品图片\" + item + ".jpg")) { //需要判断是否存在图片 Image img = I ...

  10. (十三)UITableView数据模型化

    多组数据的TableView的设计方法:每一组用一个模型对象表示. 模型包含了标题数据和行数据的数组,在控制器里包含模型的组来对各个模型进行初始化. 在tableView相应的方法中,从控制器的模型组 ...