結果

問題 No.1779 Magical Swap
ユーザー WizistWizist
提出日時 2021-12-12 22:56:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 477 ms / 2,000 ms
コード長 567 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 94,264 KB
最終ジャッジ日時 2023-09-28 16:42:48
合計ジャッジ時間 4,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
77,376 KB
testcase_01 AC 90 ms
76,956 KB
testcase_02 AC 175 ms
79,120 KB
testcase_03 AC 92 ms
77,312 KB
testcase_04 AC 122 ms
91,548 KB
testcase_05 AC 102 ms
86,036 KB
testcase_06 AC 105 ms
87,592 KB
testcase_07 AC 118 ms
91,012 KB
testcase_08 AC 91 ms
77,464 KB
testcase_09 AC 107 ms
80,932 KB
testcase_10 AC 159 ms
93,576 KB
testcase_11 AC 129 ms
88,800 KB
testcase_12 AC 101 ms
78,308 KB
testcase_13 AC 142 ms
89,812 KB
testcase_14 AC 164 ms
93,604 KB
testcase_15 AC 477 ms
79,936 KB
testcase_16 AC 130 ms
94,264 KB
testcase_17 AC 177 ms
78,772 KB
testcase_18 AC 88 ms
77,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def lcm(x, y): return x * y // math.gcd(x, y)

N = 100001
fp = [0] * N
for i in range(2, len(fp)):
	if fp[i] == 0:
		fp[i] = i
		for j in range(i * i, len(fp), i):
			if fp[j] == 0: fp[j] = i

ncases = int(input())
for caseno in range(ncases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	def check():
		if a[0] != b[0]: return False
		for i in range(1, len(a)):
			if a[i] == b[i]: continue
			if lcm(fp[i + 1], 2) > n: return False
		a.sort(); b.sort()
		return a == b

	print("Yes" if check() else "No")
0