結果

問題 No.167 N^M mod 10
ユーザー 6soukiti296soukiti29
提出日時 2017-10-19 21:40:45
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,755 bytes
コンパイル時間 5,042 ms
コンパイル使用メモリ 65,668 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 00:18:30
合計ジャッジ時間 6,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'strutils' [UnusedImport]

ソースコード

diff #

import sequtils,strutils

proc ctoi(c : char): int =
    return ord(c) - ord('0')
    
proc stringmod(s : string, m : int) : int =
    var
        ans = 0
    for i in 0..s.high:
        ans *= 10
        ans += s[i].ctoi
        ans = ans mod m
    return ans

var
    N = stdin.readline
    M = stdin.readline
    t : int
    m = N[^1].ctoi
    e = m * m

if M == "0":
    echo 1
else:
    if m == 0:
        echo 0
        
    elif m == 1:
        echo 1
        
    elif m == 2:
        case stringmod(M, 4)
        of 0:
            echo 6
        of 1:
            echo 2
        of 2:
            echo 4
        of 3:
            echo 8
        else:
            discard
            
    elif m == 3:
        case stringmod(M, 4)
        of 0:
            echo 1
        of 1:
            echo 3
        of 2:
            echo 9
        of 3:
            echo 7
        else:
            discard
            
    elif m == 4:
        case stringmod(M, 2)
        of 0:
            echo 6
        of 1:
            echo 4
        else:
            discard
            
        
    elif m == 5:
        echo 5
        
    elif m == 6:
        echo 6
        
    elif m == 7:
        case stringmod(M, 4)
        of 0:
            echo 1
        of 1:
            echo 7
        of 2:
            echo 9
        of 3:
            echo 3
        else:
            discard
            
    elif m == 8:
        case stringmod(M, 4)
        of 0:
            echo 6
        of 1:
            echo 8
        of 2:
            echo 4
        of 3:
            echo 2
        else:
            discard
    
    elif m == 9:
        case stringmod(M, 2)
        of 0:
            echo 1
        of 1:
            echo 9
        else:
            discard
0