結果

問題 No.16 累乗の加算
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-01-05 17:05:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,796 ms / 5,000 ms
コード長 685 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 73,340 KB
実行使用メモリ 394,164 KB
最終ジャッジ日時 2023-09-08 12:13:30
合計ジャッジ時間 28,457 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,796 ms
394,060 KB
testcase_01 AC 1,787 ms
394,048 KB
testcase_02 AC 1,785 ms
393,928 KB
testcase_03 AC 1,792 ms
393,932 KB
testcase_04 AC 1,766 ms
393,936 KB
testcase_05 AC 1,767 ms
393,968 KB
testcase_06 AC 1,767 ms
393,920 KB
testcase_07 AC 1,765 ms
393,924 KB
testcase_08 AC 1,768 ms
393,972 KB
testcase_09 AC 1,779 ms
394,008 KB
testcase_10 AC 1,768 ms
393,928 KB
testcase_11 AC 1,766 ms
394,164 KB
testcase_12 AC 1,786 ms
393,992 KB
testcase_13 AC 1,782 ms
393,964 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: iteration 99999999 invokes undefined behavior [-Waggressive-loop-optimizations]
         M[i] = a;
         ~~~~~^~~
main.cpp:29:24: note: within this loop
     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