hud.1017 A Mathematical Curiosity

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;
}
}
水题一道,注意格式。

你可能感兴趣的:(hud.1017 A Mathematical Curiosity)