結果

問題 No.251 大きな桁の復習問題(1)
ユーザー fmhrfmhr
提出日時 2015-08-01 07:45:29
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 11,603 ms
コンパイル使用メモリ 223,656 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 03:17:13
合計ジャッジ時間 12,530 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := readLine()
	M := readLine()
	//fmt.Println(pow(N, M))
	n := []rune(N)
	m := []rune(M)
	var n1, m1 int
	for _, v := range n {
		n1 = (n1*10+(int(v)-int('0')))%MOD
	}
	for _, v := range m {
		m1 = (m1*10+(int(v)-int('0')))%MOD
	}
	//fmt.Println(n1, m1)
	fmt.Println(pow(n1, m1))
}

// 繰り返し二乗法
// http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=NTL_1_B
// O(log(2)n)
const MOD = 129402307
func pow(x, n int) int {
	tmp := 1
	if n > 0 {
		tmp = pow(x, n/2)
		if n%2 == 0 {
			tmp = (tmp * tmp) % MOD
		} else {
			tmp = (((tmp * tmp) % MOD) * x) % MOD
		}
	}
	return tmp
}



///////////////////////////////////////////////////
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
0