結果

問題 No.1779 Magical Swap
ユーザー titiatitia
提出日時 2021-12-08 18:45:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 114,644 KB
最終ジャッジ日時 2023-09-23 08:18:42
合計ジャッジ時間 4,667 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
99,880 KB
testcase_01 AC 119 ms
99,656 KB
testcase_02 AC 177 ms
100,856 KB
testcase_03 AC 123 ms
99,940 KB
testcase_04 AC 184 ms
112,940 KB
testcase_05 AC 148 ms
109,056 KB
testcase_06 AC 153 ms
109,320 KB
testcase_07 AC 173 ms
112,028 KB
testcase_08 AC 125 ms
100,096 KB
testcase_09 AC 143 ms
103,644 KB
testcase_10 AC 193 ms
112,864 KB
testcase_11 AC 165 ms
110,908 KB
testcase_12 AC 133 ms
100,372 KB
testcase_13 AC 172 ms
110,752 KB
testcase_14 AC 194 ms
114,644 KB
testcase_15 AC 235 ms
100,948 KB
testcase_16 AC 184 ms
114,384 KB
testcase_17 AC 189 ms
100,148 KB
testcase_18 AC 122 ms
99,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

x=10**6

import math 
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]
Primes=set(Primes)

T=int(input())
for tests in range(T):
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    
    flag=1

    if sorted(A)!=sorted(B):
        print("No")
        continue

    if A[0]!=B[0]:
        print("No")
        continue

    for i in range(N):
        if (i+1) in Primes and (i+1)>N//2 and A[i]!=B[i]:
            flag=0
            break

    if flag==1:
        print("Yes")
    else:
        print("No")
        

    
0