結果

問題 No.800 四平方定理
ユーザー tentententen
提出日時 2023-07-07 16:14:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 2,021 bytes
コンパイル時間 2,742 ms
コンパイル使用メモリ 86,384 KB
実行使用メモリ 179,384 KB
最終ジャッジ日時 2023-09-28 16:50:21
合計ジャッジ時間 9,044 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
49,256 KB
testcase_01 AC 55 ms
51,648 KB
testcase_02 AC 53 ms
49,568 KB
testcase_03 AC 53 ms
51,408 KB
testcase_04 AC 54 ms
49,204 KB
testcase_05 AC 52 ms
49,276 KB
testcase_06 AC 55 ms
51,764 KB
testcase_07 AC 58 ms
52,792 KB
testcase_08 AC 54 ms
51,360 KB
testcase_09 AC 55 ms
51,608 KB
testcase_10 AC 159 ms
115,888 KB
testcase_11 AC 153 ms
123,472 KB
testcase_12 AC 158 ms
122,284 KB
testcase_13 AC 142 ms
119,120 KB
testcase_14 AC 146 ms
125,480 KB
testcase_15 AC 155 ms
123,316 KB
testcase_16 AC 150 ms
125,088 KB
testcase_17 AC 146 ms
125,272 KB
testcase_18 AC 165 ms
125,100 KB
testcase_19 AC 171 ms
123,620 KB
testcase_20 AC 47 ms
49,552 KB
testcase_21 AC 46 ms
49,444 KB
testcase_22 AC 164 ms
125,332 KB
testcase_23 AC 239 ms
179,292 KB
testcase_24 AC 217 ms
179,384 KB
testcase_25 AC 234 ms
178,976 KB
testcase_26 AC 46 ms
49,372 KB
testcase_27 AC 46 ms
49,212 KB
testcase_28 AC 215 ms
178,444 KB
testcase_29 AC 230 ms
178,856 KB
testcase_30 AC 219 ms
178,812 KB
testcase_31 AC 204 ms
170,328 KB
testcase_32 AC 216 ms
179,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int d = sc.nextInt();
        long[] countsA = new long[n * n * 2 + 1];
        long[] countsB = new long[n * n * 2 + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                countsA[i * i + j * j]++;
                int x = i * i + d - j * j;
                if (x >= 1 && x <= n * n * 2) {
                    countsB[x]++;
                }
            }
        }
        long ans = 0;
        for (int i = 0; i <= n * n * 2; i++) {
            ans += countsA[i] * countsB[i];
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0