結果

問題 No.800 四平方定理
ユーザー ameame
提出日時 2019-03-17 23:35:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 71,428 KB
実行使用メモリ 121,276 KB
最終ジャッジ日時 2023-09-22 14:12:16
合計ジャッジ時間 9,773 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,916 KB
testcase_01 AC 133 ms
57,824 KB
testcase_02 AC 130 ms
55,652 KB
testcase_03 AC 132 ms
56,164 KB
testcase_04 AC 128 ms
55,944 KB
testcase_05 AC 133 ms
56,112 KB
testcase_06 AC 136 ms
57,828 KB
testcase_07 AC 133 ms
58,036 KB
testcase_08 AC 134 ms
57,752 KB
testcase_09 AC 133 ms
57,908 KB
testcase_10 AC 196 ms
90,548 KB
testcase_11 AC 184 ms
94,216 KB
testcase_12 AC 187 ms
94,280 KB
testcase_13 AC 181 ms
92,156 KB
testcase_14 AC 183 ms
94,168 KB
testcase_15 AC 184 ms
94,340 KB
testcase_16 AC 188 ms
94,372 KB
testcase_17 AC 187 ms
94,300 KB
testcase_18 AC 188 ms
94,604 KB
testcase_19 AC 188 ms
94,268 KB
testcase_20 AC 122 ms
55,648 KB
testcase_21 AC 123 ms
55,568 KB
testcase_22 AC 189 ms
94,100 KB
testcase_23 AC 228 ms
120,948 KB
testcase_24 AC 223 ms
120,860 KB
testcase_25 AC 230 ms
121,020 KB
testcase_26 AC 124 ms
56,624 KB
testcase_27 AC 130 ms
56,004 KB
testcase_28 AC 222 ms
121,276 KB
testcase_29 AC 229 ms
121,120 KB
testcase_30 AC 221 ms
121,016 KB
testcase_31 AC 216 ms
116,956 KB
testcase_32 AC 227 ms
119,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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