結果

問題 No.16 累乗の加算
ユーザー opqopq_
提出日時 2015-05-25 17:31:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 488 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 22,912 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 08:25:05
合計ジャッジ時間 887 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d%d", &x, &N);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:21:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         for (int i = 0; i < N; i++) scanf("%d", a+i);
      |                                     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
using namespace std;

#define MOD 1000003
#define N_MAX 100
int x, N;
int a[N_MAX];

long long PowMod(long long x, long long n, long long mod) {
	long long ret = 1;
	while (0 < n) {
		if (n & 1) ret = ret * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return ret;
}

int main() {
	scanf("%d%d", &x, &N);
	for (int i = 0; i < N; i++) scanf("%d", a+i);
	
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += PowMod(x, a[i], MOD);
	}
	
	printf("%d\n", res);
	
	return 0;
}

0