結果

問題 No.2496 LCM between Permutations
ユーザー yupoohyupooh
提出日時 2023-10-06 22:03:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,376 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 93,772 KB
平均クエリ数 953.17
最終ジャッジ日時 2023-10-06 22:03:32
合計ジャッジ時間 6,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 97 ms
87,688 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
n=int(input())
if n==1:
  print("!",1,1,flush=True)
  exit()
for i in range(n,0,-1):
  if isprime(i):
    x=i
    break
l=[]
for i in range(n):
  print("?",1,i+1,flush=True)
  l.append(int(input()))
cnt=0
for i in range(n):
  if l[i]%x==0:
    cnt+=1
    idx=i
if cnt==n:
  B=[]
  for i in l:
    B.append(i//x)
  for i in range(n):
    if B[i]==x:
      idx=i
      break
  A=[]
  for i in range(n):
    print("?",i+1,idx+1,flush=True)
    A.append(int(input())//x)
  A+=B
  print("!",*A,flush=True)
  exit()
A=[]
for i in range(n):
  print("?",i+1,idx+1,flush=True)
  A.append(int(input())//x)
for i in range(n):
  if A[i]==x:
    idx=i
    break
B=[]
for i in range(n):
  print("?",idx+1,i+1,flush=True)
  B.append(int(input())//x)
A+=B
print("!",*A,flush=True)
exit()  
0