結果

問題 No.16 累乗の加算
ユーザー fmhrfmhr
提出日時 2015-07-29 18:42:21
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 425 bytes
コンパイル時間 10,367 ms
コンパイル使用メモリ 224,772 KB
実行使用メモリ 10,420 KB
最終ジャッジ日時 2024-04-19 03:09:50
合計ジャッジ時間 16,877 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	solve()
}

func solve(){
	var x, N, a, ans int
	fmt.Scan(&x, &N)
	for i:=0; i<N; i++{
		fmt.Scan(&a)
		ans += ppow(x, a)
	}
	fmt.Println(ans)
}

func ppow(x, a int)int{
	if a == 1{
		return 1
	}else if a%2==0{
		return pow(x*x, a/2)
	}else{
		return pow(x*x, a/2)*x
	}
}

const MOD = 1000003
func pow(x, n int)int{
	r := 1
	for i:=0; i<n; i++{
		r = r * x % MOD

	}
	return r
}
0