結果

問題 No.16 累乗の加算
ユーザー tetsuzuki1115
提出日時 2018-01-05 17:05:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1,788 ms / 5,000 ms
コード長 685 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 79,572 KB
実行使用メモリ 394,076 KB
最終ジャッジ日時 2024-06-26 05:26:36
合計ジャッジ時間 28,065 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 #

#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