結果

問題 No.147 試験監督(2)
ユーザー 6soukiti296soukiti29
提出日時 2017-09-16 16:50:23
言語 Nim
(2.0.2)
結果
AC  
実行時間 1,911 ms / 2,000 ms
コード長 2,292 bytes
コンパイル時間 3,257 ms
コンパイル使用メモリ 68,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 15:12:08
合計ジャッジ時間 11,438 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,906 ms
4,376 KB
testcase_01 AC 1,911 ms
4,380 KB
testcase_02 AC 1,907 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,strscans
const
    m : int64 = 1_000_000_007

var
    N = stdin.readline.parseInt
    ans, c : int64
    s,d,cs : string

proc ctoi(c : char) : int =
    return ord(c) - ord('0')
   
proc pows(i : int64, s : string) : int64 =
    if s == "0" or s == "":
        return 1
    elif s == "1":
        return i mod m
    elif (s[^1].ctoi and 1) == 1:
        return (i * pows(i, s[0..<s.high] & $(s[^1].ctoi - 1))) mod m
    else:
        var
            s2 : string = ""
            flag : bool
        for j in 0..s.high:
            var k : string
            if flag == true:
                k = $((10 + s[j].ctoi) div 2)
            else:
                k = $(s[j].ctoi div 2)
            if (s[j].ctoi and 1) == 1:
                flag = true
            else:
                flag = false
            if k != "0" or j != 0:
                s2 &= k
        return pows((i * i) mod m, s2) mod m
        
    

type
    Matrix[H,W: static[int]] = 
        array[1..H,array[1..W,int64]]
        
proc `+`[H,W](a,b:Matrix[H,W]):Matrix[H,W] =
    for i in 1..high(a):
        for j in 1..high(a[0]):
            result[i][j] = a[i][j] + b[i][j]
            
proc `*`[Ha,Wa,Wb](a:Matrix[Ha,Wa],b:Matrix[Wa,Wb]):Matrix[Ha,Wb] =
    var k : int64
    for i in 1.. Ha:
        for j in 1..Wb:
            k = 0
            for ai in 1..Wa:
                k = (k + a[i][ai] * b[ai][j]) mod m
            result[i][j] = k
proc powMatrix[W,H](a : Matrix[W,H], n : int64):Matrix[W,H] =
    if n == 1:
        return a
    if n mod 2 == 0:
        return powMatrix(a * a,n div 2)
    else:
        return powMatrix(a * a,n div 2) * a
        
proc printMatrix(A: Matrix)=
    for a in A:
        echo a.join(", ")
        
proc fib(n : int64): int64 =
    if n == 0:
        return 0
    var
        A : Matrix[2,2] = [[1.int64,1.int64],[1.int64,0.int64]]
    return (powMatrix(A,n))[2][1] mod m


const
    t = 1_000_000_006
    
ans = 1
for n in 1..N:
    s = stdin.readline
    discard scanf(s, "$* $*", cs, d)
    c = cs.parseBiggestInt
    while d.len > 11:
        var
            p = d[0..10].parseBiggestInt
            q = p mod t
        d = $q & d[11..d.high]
        
        
    ans = (ans * pows(fib((c + 2) mod 2_000_000_016) , d)) mod m
    #echo ans
echo ans
0