杭电oj(Java版)——1017 A Mathematical Curiosity
来源:互联网 发布:二战德军军服 淘宝 编辑:程序博客网 时间:2024/06/05 03:54
A Mathematical Curiosity
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40702 Accepted Submission(s): 13072
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.
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
110 120 330 40 0
Sample Output
Case 1: 2Case 2: 4Case 3: 5import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int Case = 0;int n = 0;int m = 0;int t = scanner.nextInt();while (t-- > 0) {while (scanner.hasNext()) {n = scanner.nextInt();m = scanner.nextInt();int num = 0;if (n == 0 && m == 0) {break;}Case++;for (int i = 1; i < n - 1; i++) {for (int j = i + 1; j < n; j++) {if ((i * i + j * j + m) % (i * j) == 0) {num++;}}}System.out.println("Case " + Case + ": " + num);}Case = 0;if (t!=0) {System.out.println();}}}}
0 0
- 杭电oj(Java版)——1017 A Mathematical Curiosity
- 杭电OJ—— 1017 A Mathematical Curiosity
- 杭电acm—1017 A Mathematical Curiosity
- 杭电1017——A Mathematical Curiosity(简单题)
- 杭电1017 A Mathematical Curiosity
- 杭电ACM 1017 A Mathematical Curiosity
- 杭电 acm 1017 A Mathematical Curiosity
- 杭电1017 A Mathematical Curiosity
- 杭电1017 之 A Mathematical Curiosity
- 杭电 1017 A Mathematical Curiosity
- HDU—— 1017 A Mathematical Curiosity
- 杭电OJ_DIY_YTW2_1001 A Mathematical Curiosity
- 杭电ACM1017 A Mathematical Curiosity
- hdu-oj 1017 A Mathematical Curiosity
- Hdu oj 1017 A Mathematical Curiosity
- 杭电ACM OJ 1017 A Mathematical Curiosity 题很简单,就是题目意思太让人费解了!
- 1017 A Mathematical Curiosity
- 1017 A Mathematical Curiosity
- JS的事件监听机制
- Linux下的tar压缩解压缩命令详解
- 线性表之顺序表
- Volley源码阅读之网络分发器(NetworkDispatcher)的工作原理
- 一个java文件可以有多个类嘛?
- 杭电oj(Java版)——1017 A Mathematical Curiosity
- js用正则表达式获取地址栏参数
- Linux基本语法5
- Convert Sorted Array to Binary Search Tree
- 面向对象的三个特征
- Flink Scala API Extensions学习笔记以及翻译
- socket/TCP/UDP基础及Unity聊天室的实现
- C++输入输出流格式控制
- python之list.append()和list.extend(list)的区别