結果

問題 No.1232 2^x = x
ユーザー dot_haraaidot_haraai
提出日時 2021-06-03 22:32:27
言語 Nim
(2.0.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 4,081 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 17:32:26
合計ジャッジ時間 5,159 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport]
/home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport]
/home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(2, 37) Warning: imported and not used: 'deques' [UnusedImport]
/home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport]
/home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport]
/home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport]

ソースコード

diff #

import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets
import critbits, future, strformat, deques
template `max=`(x,y) = x = max(x,y)
template `min=`(x,y) = x = min(x,y)
template `mod=`(x,y) = x = x mod y
template scan2 = (scan(), scan())
template scan3 = (scan(), scan())
let read* = iterator: string {.closure.} =
    while true: (for s in stdin.readLine.split: yield s)
proc scan(): int = read().parseInt
proc scanf(): float = read().parseFloat
proc toInt(c:char): int =
    return int(c) - int('0')


# 拡張ユークリッド互除法

proc xgcd(a,b:int):(int,int,int)=
  var
    b = b
    x0=1
    y0=0
    x1=0
    y1=1
    q:int
    a = a
  while b!=0:
    (q,a,b) = (a.div(b),b,a.mod(b))
    (x0,x1)=(x1,x0-q*x1)
    (y0,y1)=(y1,y0-q*y1)
  return (a,x0,y0)

# modの逆元
proc modinv(a,m:int):int=
  var (g,x,y)=xgcd(a,m)
  if g!=1:
    return -1
  else:
    return x mod m

# 中国剰余定理
proc crt(b:seq[int],m:seq[int]):(int,int)=
  var
    r=0
    M=1
  for i in 0..<b.len:
    var (d,p,q)=xgcd(M,m[i])
    if ((b[i]-r)mod d) != 0:return (0,-1)
    var tmp = (b[i]-r) div d * p mod (m[i] div d)
    r+=M*tmp
    M*=m[i] div d
  if r<0:
    r+=M
  r.mod=M

  return (r,M)



# modPow
# 無いので作る
# なんか畳み込んで上手いことやるやつ
proc modPow(x,b,m:int):int=
  if b == 0:
    return 1
  if x == 0:
    return 0
  if b == 1:
    return x
  return (modPow((x^2) mod m, b div 2, m) * x^(b mod 2)) mod m




proc solve()=
  var
    n = scan()
    ps = newseqwith(n,scan())
  for p in ps:
    if p==2:
      echo 2
    else:
      var n = (modInv(p-1,p)+p).mod(p)
      echo n*(p-1)

solve()
0