結果

問題 No.16 累乗の加算
ユーザー prog470prog470
提出日時 2016-09-24 16:20:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 981 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 70,320 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 07:12:22
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

long long dp[100000005] = {}, MOD = 1000003;

long long pow(long long x, long long n) {
	if (n == 0) return 1;
	long long ret;
	ret = pow(x * x % MOD, n / 2) % MOD;
	if (n % 2 != 0) ret = ret * x % MOD;
	return ret;
}

int main() {

	long long x, N, a[105], ans = 0;
	cin >> x >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	/*
	sort(a,a+N);
	long long cnt = 1;

	for (int j = 0; j < a[0]; j++) {
		cnt = cnt * x % MOD;
	}
	ans = cnt;
	//cout << 0 << ": " << cnt << endl;

	for (int i = 1; i < N; i++) {
		for (int j = a[i-1]; j < a[i]; j++) {
			cnt = cnt * x % MOD;
		}
		//cout <<i<< ": " << cnt << endl;
		ans = (ans + cnt) % MOD;
	}
	*/

	for (int i = 0; i < N; i++) {
		ans += pow(x, a[i]);
	}

	cout << ans << endl;

	return 0;
}
0