結果

問題 No.1218 Something Like a Theorem
ユーザー 双六双六
提出日時 2020-09-07 01:43:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 76,428 KB
最終ジャッジ日時 2023-08-19 14:37:20
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,568 KB
testcase_01 AC 79 ms
71,480 KB
testcase_02 AC 80 ms
71,808 KB
testcase_03 AC 79 ms
71,592 KB
testcase_04 AC 78 ms
71,364 KB
testcase_05 AC 83 ms
71,760 KB
testcase_06 AC 79 ms
71,720 KB
testcase_07 AC 80 ms
71,636 KB
testcase_08 AC 84 ms
76,292 KB
testcase_09 AC 84 ms
76,428 KB
testcase_10 AC 81 ms
71,572 KB
testcase_11 AC 81 ms
71,376 KB
testcase_12 AC 77 ms
71,328 KB
testcase_13 AC 82 ms
71,680 KB
testcase_14 AC 78 ms
71,632 KB
testcase_15 AC 81 ms
71,192 KB
testcase_16 AC 80 ms
71,804 KB
testcase_17 AC 85 ms
71,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

# ニュートン法によるK乗根計算
def sqrt(N, k = 2):
	l = k - 1
	if not N:
		return 0
	y = 1 << (N.bit_length() + l) // k
	x = y + 1
	while y < x:
		x = y
		y = (l * x + N // (x ** l)) // k

	return x


#処理内容
def main():
	N, Z = getlist()
	if N >= 3:
		print("No")
		return

	if N == 1:
		if Z == 1:
			print("No")
		else:
			print("Yes")
		return

	for x in range(1, Z):
		dif = Z ** 2 - x ** 2
		y = sqrt(dif)
		if y ** 2 == dif:
			print("Yes")
			return

	print("No")

if __name__ == '__main__':
	main()
0