結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2015-05-18 18:11:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 576 bytes |
コンパイル時間 | 128 ms |
コンパイル使用メモリ | 23,040 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 04:53:25 |
合計ジャッジ時間 | 712 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d%d", &x, &N); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:11:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | for (int i = 0; i < N; i++) scanf("%d", a + i); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio> using namespace std; #define MOD 1000003 #define N_MAX 100 int x, N; int a[N_MAX]; int main() { scanf("%d%d", &x, &N); for (int i = 0; i < N; i++) scanf("%d", a + i); long long res = 0; for (int i = 0; i < N; i++) { long long yy = 1; while (2 < a[i]) { long long y, z; y = a[i] ? x : 1; z = 1; while (z * 2 < a[i]) { y *= y; y %= MOD; z *= 2; } a[i] -= z; yy *= y; yy %= MOD; } while (a[i]) { yy *= x; yy %= MOD; a[i]--; } res += yy; res %= MOD; } printf("%lld\n", res); return 0; }