結果

問題 No.147 試験監督(2)
ユーザー 6soukiti296soukiti29
提出日時 2017-09-16 17:00:07
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,815 bytes
コンパイル時間 3,379 ms
コンパイル使用メモリ 69,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 15:12:26
合計ジャッジ時間 4,615 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
4,384 KB
testcase_01 AC 139 ms
4,376 KB
testcase_02 AC 139 ms
4,380 KB
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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, d : int64
    s, ds, cs : string

proc ctoi(c : char) : int =
    return ord(c) - ord('0')
   
        
proc powInt(n : int64, m : int64, k = 1_000_000_007):int64 =
    if m == 0:
        return 1
    elif m == 1:
        return (n mod k)
    if (m mod 2) == 0:
        return powInt((n*n) mod k,m div 2, k) mod k
    else:
        return (powInt((n*n) mod k,m div 2, k) * n) mod k

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, ds)
    c = cs.parseBiggestInt
    d = 0
    for i in 0..ds.high:
        d *= 10
        d += ds[i].ctoi
        d = d mod t
        
    ans = (ans * powInt(fib((c + 2) mod 2_000_000_016) , d)) mod m
    #echo ans
echo ans
0