結果

問題 No.1593 Perfect Distance
ユーザー GrayCoderGrayCoder
提出日時 2021-07-09 22:31:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 685 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 12,900 KB
最終ジャッジ日時 2023-09-14 09:47:46
合計ジャッジ時間 6,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,484 KB
testcase_01 AC 17 ms
8,516 KB
testcase_02 AC 18 ms
8,624 KB
testcase_03 AC 18 ms
8,608 KB
testcase_04 AC 18 ms
8,580 KB
testcase_05 AC 18 ms
8,536 KB
testcase_06 AC 18 ms
8,612 KB
testcase_07 AC 19 ms
8,508 KB
testcase_08 AC 24 ms
8,464 KB
testcase_09 AC 189 ms
8,468 KB
testcase_10 AC 1,353 ms
8,612 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from sys import stdin


def is_sqrt(n):
    idx = defaultdict(int)
    while n >= 4:
        if n % 2:
            break
        else:
            n //= 2
            idx[2] += 1
    i = 3
    while n >= i * i:
        if n % i:
            i += 2
        else:
            n //= i
            idx[i] += 1
    idx[n] += 1

    x = 1
    for i in idx.values():
        x *= i + 1
    ret = True if x % 2 else False
    return ret


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())

    ans = 0
    n = N * N
    for x in range(1, N):
        y = n - x * x
        if is_sqrt(y):
            ans += 1
    print(ans)


main()
0