結果

問題 No.800 四平方定理
ユーザー tentententen
提出日時 2020-09-01 08:40:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 71,968 KB
実行使用メモリ 104,212 KB
最終ジャッジ日時 2023-08-11 04:55:13
合計ジャッジ時間 10,959 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
40,156 KB
testcase_01 AC 124 ms
41,032 KB
testcase_02 AC 123 ms
40,132 KB
testcase_03 AC 124 ms
40,412 KB
testcase_04 AC 124 ms
40,168 KB
testcase_05 AC 126 ms
40,088 KB
testcase_06 AC 128 ms
41,000 KB
testcase_07 AC 130 ms
40,204 KB
testcase_08 AC 126 ms
40,720 KB
testcase_09 AC 125 ms
40,732 KB
testcase_10 AC 200 ms
72,124 KB
testcase_11 AC 192 ms
75,872 KB
testcase_12 AC 200 ms
75,380 KB
testcase_13 AC 184 ms
73,592 KB
testcase_14 AC 187 ms
76,584 KB
testcase_15 AC 196 ms
75,496 KB
testcase_16 AC 189 ms
76,480 KB
testcase_17 AC 213 ms
75,920 KB
testcase_18 AC 208 ms
76,548 KB
testcase_19 AC 201 ms
76,100 KB
testcase_20 AC 116 ms
38,984 KB
testcase_21 AC 120 ms
39,288 KB
testcase_22 AC 199 ms
76,404 KB
testcase_23 AC 268 ms
103,688 KB
testcase_24 AC 252 ms
103,740 KB
testcase_25 AC 270 ms
104,192 KB
testcase_26 AC 117 ms
39,664 KB
testcase_27 AC 117 ms
39,680 KB
testcase_28 AC 250 ms
103,984 KB
testcase_29 AC 308 ms
103,540 KB
testcase_30 AC 235 ms
103,996 KB
testcase_31 AC 226 ms
99,528 KB
testcase_32 AC 243 ms
104,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int d = sc.nextInt();
    	int max = n * n * 2;
    	int[] counts = new int[max + 1];
    	int[] sums = new int[max + 1];
    	for (int i = 1; i <= n; i++) {
    	    for (int j = 1; j <= n; j++) {
    	        counts[i * i + j * j]++;
    	        int tmp = i * i - j * j + d;
    	        if (tmp > 0 && tmp <= max) {
    	            sums[tmp]++;
    	        }
    	    }
    	}
    	long ans = 0;
    	for (int i = 1; i <= max; i++) {
    	    ans += counts[i] * sums[i];
    	}
    	System.out.println(ans);
    }
}
0