結果

問題 No.673 カブトムシ
ユーザー 6soukiti296soukiti29
提出日時 2018-04-14 00:11:45
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 3,060 ms
コンパイル使用メモリ 68,900 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 18:12:56
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 RE -
testcase_12 AC 1 ms
4,380 KB
testcase_13 RE -
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,math
var
    B,C,D,ans : int64
    M : int64 = 1_000_000_007
(B, C, D) = stdin.readline.split.map(parseBiggestInt)

if C == 1:
    echo(((B mod M) * (D mod M)) mod M)
    quit()
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:
        var n = n mod k
        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


proc inv_mod(a : int64):int64 = 
    var
        b,x,u,q,t : int64
        a = a
    b = M
    x = 1
    u = 0
    while b > 0:
        q = a div b
        t = u
        u = x - q * u
        x = t
        t = b
        b = a - q * b
        a = t
    if x < 0:
        x += M
    return x
ans = B mod M
ans = (ans * (C mod M)) mod M
ans = (ans * (powInt(C, D) - 1)) mod M
ans = (ans * inv_mod(C - 1)) mod M
echo ans
0