結果

問題 No.800 四平方定理
ユーザー tentententen
提出日時 2021-11-02 18:27:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 85,084 KB
最終ジャッジ日時 2024-04-20 04:24:54
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,052 KB
testcase_01 AC 53 ms
50,360 KB
testcase_02 AC 52 ms
50,444 KB
testcase_03 AC 54 ms
50,552 KB
testcase_04 AC 52 ms
50,520 KB
testcase_05 AC 54 ms
50,528 KB
testcase_06 AC 55 ms
49,908 KB
testcase_07 AC 55 ms
50,504 KB
testcase_08 AC 56 ms
50,360 KB
testcase_09 AC 55 ms
50,504 KB
testcase_10 AC 84 ms
68,352 KB
testcase_11 AC 85 ms
70,156 KB
testcase_12 AC 88 ms
70,312 KB
testcase_13 AC 83 ms
70,208 KB
testcase_14 AC 85 ms
70,208 KB
testcase_15 AC 89 ms
70,340 KB
testcase_16 AC 89 ms
70,348 KB
testcase_17 AC 86 ms
70,112 KB
testcase_18 AC 89 ms
70,256 KB
testcase_19 AC 92 ms
70,404 KB
testcase_20 AC 48 ms
50,328 KB
testcase_21 AC 49 ms
50,560 KB
testcase_22 AC 89 ms
70,380 KB
testcase_23 AC 118 ms
84,856 KB
testcase_24 AC 117 ms
84,832 KB
testcase_25 AC 115 ms
85,084 KB
testcase_26 AC 51 ms
50,424 KB
testcase_27 AC 51 ms
50,324 KB
testcase_28 AC 112 ms
84,840 KB
testcase_29 AC 117 ms
84,744 KB
testcase_30 AC 114 ms
84,776 KB
testcase_31 AC 108 ms
82,996 KB
testcase_32 AC 115 ms
85,028 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[] counts = new int[n * n * 2 + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                counts[i * i + j * j]++;
            }
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                int x = i * i - j * j + d;
                if (x >= 0 && x < counts.length) {
                    ans += counts[x];
                }
            }
        }
        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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0