結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
Knots_coder
|
| 提出日時 | 2022-03-26 18:03:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,531 bytes |
| コンパイル時間 | 858 ms |
| コンパイル使用メモリ | 98,148 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 09:57:40 |
| 合計ジャッジ時間 | 1,536 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <bitset>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <functional>
#include <stack>
#include <cmath>
#include <string>
#include <complex>
#include <cassert>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30)-1;
//const int MOD = 1e9+7;
const int MOD = 1000003;
const ll LINF = (1ll<<62)-1;
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";
/**
*繰り返し二乗法
*時間計算量:O(logn)
*空間計算量:O(1)
**/
long long powpow(long long x,long long n){///通常のpow
long long ret = 1;
while(n>0){
if(n&1)ret *= x;
x *= x;
n >>= 1; //nを1bit右にずらす
}
return ret;
}
long long powmod(long long x,long long n){//MODを取る時
long long ret = 1;
while(n>0){
if(n&1)ret = ret * x % MOD;
x = x*x % MOD;
n >>= 1; //nを1bit右にずらす
}
return ret;
}
int main(){
ll x,n,a;cin >> x >> n;
ll ans = 0;
REP(i,n){
cin >> a;
ans += powmod(x,a);
ans %= MOD;
}
COUT(ans);
}
Knots_coder