結果

問題 No.16 累乗の加算
コンテスト
ユーザー tetsuzuki1115
提出日時 2018-01-05 17:05:42
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 793 ms / 5,000 ms
コード長 685 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 478 ms
コンパイル使用メモリ 99,056 KB
実行使用メモリ 394,376 KB
最終ジャッジ日時 2026-03-12 20:03:27
合計ジャッジ時間 12,893 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:32:14: warning: iteration 99999999 invokes undefined behavior [-Waggressive-loop-optimizations]
   32 |         M[i] = a;
      |         ~~~~~^~~
main.cpp:29:24: note: within this loop
   29 |     for ( int i = 1; i <= 100000000; i++ ) {
      |                      ~~^~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000003;


int M[100000000];

int main() {
    
    int x,N;
    cin >> x >> N;
    
    
    M[0] = 1;
    long long a = 1;
    for ( int i = 1; i <= 100000000; i++ ) {
        a *= x;
        a %= MOD;
        M[i] = a;
    }
    
    long long ans =  0;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ans += M[a];
        ans %= MOD;
    }
    
    cout << ans << endl;
    
    return 0;
}
0