hud.1017 A Mathematical Curiosity

来源:互联网 发布:电脑数据丢失怎么办 编辑:程序博客网 时间:2024/06/18 04:50

http://acm.hdu.edu.cn/showproblem.php?pid=1017

import java.util.Scanner;public class Mathematical{public static void main(String[] args){int n,m,N;int count = 1;Scanner input = new Scanner(System.in);N = input.nextInt();while(N-- != 0){count = 1;while(true){n = input.nextInt();m = input.nextInt();if (m == 0 && n == 0){break;}else {System.out.println("Case "+count+": "+pairs(n,m));count++;}}if (N != 0){System.out.println();}}input.close();}private static int pairs(int n, int m){int count = 0;for (int i = 1; i < n; i++){for (int j = i + 1; j < n; j++){if (is(calculate(i, j, m))){count++;}}}return count;}private static double calculate(int a,int b,int m){return (Math.pow(a, 2) + Math.pow( b, 2) + m)/(a*b);}private static boolean is(double a){if (a == (int)a){return true;}return false;}}
水题一道,注意格式。

0 0
原创粉丝点击