結果

問題 No.800 四平方定理
ユーザー FromBooskaFromBooska
提出日時 2023-03-03 04:37:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 824 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 70,692 KB
最終ジャッジ日時 2023-10-17 23:14:04
合計ジャッジ時間 8,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
68,556 KB
testcase_01 AC 290 ms
66,444 KB
testcase_02 AC 195 ms
66,436 KB
testcase_03 AC 222 ms
64,380 KB
testcase_04 AC 172 ms
66,444 KB
testcase_05 AC 192 ms
66,444 KB
testcase_06 AC 365 ms
64,388 KB
testcase_07 AC 299 ms
66,444 KB
testcase_08 AC 667 ms
64,380 KB
testcase_09 AC 320 ms
66,456 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# N<2000なので3重ループは間に合わないが2重ループは可能
# たとえばx, yを全探索
# x, yを決め打てば(z-w)*(z+w) = 定数
# その定数の約数組合せで成り立つ数を加える

from math import floor
N, D = map(int, input().split())

count = 0
for x in range(1, N+1):
    for y in range(1, N+1):
        A = abs(D - x**2-y**2)
        if A == 0:
            count += N
            #print('x', x, 'y', y, 'A', A)
        else:
            i = 1
            while i*i < A:
                # i**2=Aだと(w-z)=(w+z)となり成り立たない
                if A%i == 0:
                    if A//i <= N*2 and (i + A//i)%2 == 0 and (i + A//i)//2 <= N:
                        count += 1
                        #print('x', x, 'y', y, 'A', A, 'i', i)
                i += 1
print(count)
0