結果

問題 No.167 N^M mod 10
コンテスト
ユーザー 6soukiti29
提出日時 2017-10-19 21:40:45
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,755 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,338 ms
コンパイル使用メモリ 66,048 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-10 07:06:31
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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 #
raw source code

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