結果

問題 No.147 試験監督(2)
ユーザー 6soukiti296soukiti29
提出日時 2017-09-16 13:14:34
言語 Nim
(2.0.0)
結果
RE  
実行時間 -
コード長 2,047 bytes
コンパイル時間 2,994 ms
コンパイル使用メモリ 68,208 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 15:11:29
合計ジャッジ時間 4,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
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
    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
    elif (s[^1].ctoi and 1) == 1:
        return i * pows(i, s[0..<s.high] & $(s[^1].ctoi - 1))
    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]
    
ans = 1
for line in stdin.lines:
    discard scanf(line, "$* $*", cs, d)
    c = cs.parseBiggestInt
    ans = (ans * pows(fib(c + 2), d)) mod m

echo ans
0