結果

問題 No.1779 Magical Swap
ユーザー lanegue
提出日時 2021-12-25 19:39:37
言語 D
(dmd 2.109.1)
結果
RE  
実行時間 -
コード長 761 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 240,636 KB
実行使用メモリ 8,588 KB
最終ジャッジ日時 2024-06-22 13:55:22
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 17 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const int N_MAX = 10 ^^ 5;
int[] primes;

bool solve(){
	auto N = readln.chomp.to!int;
	auto A = readln.chomp.split(" ").to!(int[]);
	auto B = readln.chomp.split(" ").to!(int[]);
	if(A[0] != B[0]) return false;
	auto i = primes.countUntil!(a => (a * 2 > N));
	auto j = primes.countUntil!(a => (a > N));
	foreach(p; primes[i .. j]){
		if(A[p - 1] != B[p - 1]) return false;
	}
	if(A.sort != B.sort) return false;
	return true;
}

void main(){
	auto T = readln.chomp.to!int;
	primes ~= 2;
	for(auto n = 3; n <= N_MAX; n += 2){
		auto f = true;
		foreach(p; primes){
			if(n % p == 0){
				f = false;
				break;
			}
		}
		if(f){
			primes ~= n;
		}
	}
	for(auto t = 0; t < T; t++){
		if(solve){
			writeln("Yes");
		}else{
			writeln("No");
		}
	}
}
0