結果

問題 No.167 N^M mod 10
ユーザー tnoda_
提出日時 2015-04-02 16:09:29
言語 Go
(1.23.4)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 335 bytes
コンパイル時間 12,048 ms
コンパイル使用メモリ 223,012 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 01:13:27
合計ジャッジ時間 13,204 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"strconv"
)

func mod4(s string) int {
	l := len(s)
	if l > 2 {
		s = s[l-2:]
	}
	x, _ := strconv.Atoi(s)
	return x % 4
}

func main() {
	var N, M string
	fmt.Scan(&N, &M)
	n := int(N[len(N)-1] - '0')
	x := 1
	for i := 0; i < mod4(M)+4; i++ {
		x *= n
	}
	if M == "0" {
		x = 1
	}
	fmt.Println(x % 10)
}
0