ZOJ-1239

来源:互联网 发布:成都科来软件 编辑:程序博客网 时间:2024/05/18 09:12
import java.util.Scanner;public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int n = sc.nextInt();for (int i = 0; i < n; i++){int m = sc.nextInt();int[] pegs = new int[m];int max = 0;while (true){max++;int j;for (j = 0; j < m; j++){if (pegs[j] != 0){if (isSquare(max + pegs[j])){pegs[j] = max;break;}continue;}pegs[j] = max;break;}if (j == m){System.out.println(max - 1);break;}}}}static boolean isSquare(int number){return (Math.sqrt(number) - (int) Math.sqrt(number)) == 0;}}

0 0
原创粉丝点击