結果

問題 No.800 四平方定理
ユーザー tentententen
提出日時 2022-10-20 16:03:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,505 bytes
コンパイル時間 6,038 ms
コンパイル使用メモリ 74,280 KB
実行使用メモリ 117,664 KB
最終ジャッジ日時 2023-09-12 21:07:59
合計ジャッジ時間 8,157 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,668 KB
testcase_01 AC 49 ms
49,396 KB
testcase_02 AC 47 ms
49,368 KB
testcase_03 AC 48 ms
49,672 KB
testcase_04 AC 47 ms
49,276 KB
testcase_05 AC 47 ms
49,296 KB
testcase_06 AC 54 ms
49,660 KB
testcase_07 AC 51 ms
49,300 KB
testcase_08 AC 55 ms
49,856 KB
testcase_09 AC 50 ms
49,324 KB
testcase_10 AC 122 ms
84,740 KB
testcase_11 AC 113 ms
88,276 KB
testcase_12 AC 117 ms
87,944 KB
testcase_13 AC 105 ms
87,852 KB
testcase_14 AC 116 ms
90,040 KB
testcase_15 AC 116 ms
89,972 KB
testcase_16 AC 109 ms
89,768 KB
testcase_17 AC 108 ms
90,060 KB
testcase_18 AC 121 ms
90,104 KB
testcase_19 AC 123 ms
89,972 KB
testcase_20 AC 43 ms
49,264 KB
testcase_21 AC 43 ms
49,640 KB
testcase_22 AC 122 ms
87,884 KB
testcase_23 AC 180 ms
116,176 KB
testcase_24 AC 167 ms
116,196 KB
testcase_25 AC 171 ms
116,012 KB
testcase_26 AC 42 ms
49,292 KB
testcase_27 AC 44 ms
49,380 KB
testcase_28 AC 157 ms
117,664 KB
testcase_29 AC 166 ms
116,596 KB
testcase_30 AC 153 ms
116,308 KB
testcase_31 AC 149 ms
111,520 KB
testcase_32 AC 165 ms
116,060 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[] lefts = new int[max + 1];
        int[] rights = new int[max + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                lefts[i * i + j * j]++;
                int x = i * i + d - j * j;
                if (x > 0 && x <= max) {
                    rights[x]++;
                }
            }
        }
        long ans = 0;
        for (int i = 1; i <= max; i++) {
            ans += lefts[i] * rights[i];
        }
        System.out.println(ans);
    }
    
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0