結果

問題 No.800 四平方定理
ユーザー tentententen
提出日時 2022-08-12 10:15:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,497 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 77,504 KB
実行使用メモリ 119,204 KB
最終ジャッジ日時 2023-10-23 20:18:16
合計ジャッジ時間 6,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,500 KB
testcase_01 AC 58 ms
53,500 KB
testcase_02 AC 56 ms
53,496 KB
testcase_03 AC 57 ms
53,500 KB
testcase_04 AC 56 ms
53,504 KB
testcase_05 AC 56 ms
53,504 KB
testcase_06 AC 59 ms
53,496 KB
testcase_07 AC 57 ms
53,504 KB
testcase_08 AC 60 ms
54,056 KB
testcase_09 AC 58 ms
53,548 KB
testcase_10 AC 131 ms
88,532 KB
testcase_11 AC 118 ms
92,424 KB
testcase_12 AC 122 ms
90,396 KB
testcase_13 AC 111 ms
90,364 KB
testcase_14 AC 115 ms
92,456 KB
testcase_15 AC 121 ms
92,452 KB
testcase_16 AC 114 ms
92,460 KB
testcase_17 AC 115 ms
92,468 KB
testcase_18 AC 124 ms
92,444 KB
testcase_19 AC 129 ms
92,428 KB
testcase_20 AC 51 ms
53,492 KB
testcase_21 AC 51 ms
53,500 KB
testcase_22 AC 125 ms
92,460 KB
testcase_23 AC 166 ms
119,180 KB
testcase_24 AC 155 ms
119,204 KB
testcase_25 AC 166 ms
119,188 KB
testcase_26 AC 51 ms
53,500 KB
testcase_27 AC 50 ms
53,492 KB
testcase_28 AC 153 ms
119,172 KB
testcase_29 AC 166 ms
119,200 KB
testcase_30 AC 156 ms
119,196 KB
testcase_31 AC 148 ms
115,068 KB
testcase_32 AC 161 ms
119,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

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

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0