結果

問題 No.16 累乗の加算
ユーザー NaruYNaruY
提出日時 2018-05-09 10:23:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,175 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 173,076 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 11:16:04
合計ジャッジ時間 2,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);i++)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
const ll p = 1000003;
map<int,ll>dic;

ll ppow(ll x,ll n){
	if (dic[n] != 0) return dic[n];
	
	if (n % 2 == 0){
		dic[n] = (ppow(x,n/2) * ppow(x,n/2)) % p; 
		return dic[n];
	}else{
		dic[n] = (x * ppow(x,n/2) * ppow(x,n/2) % p) % p;
		return dic[n];
	}

}

int main(){
	ll ans = 0;
	ll x,N; scanf("%lld%lld",&x,&N);
	ll a[101];

	REP(i,N){
		ll z; scanf("%lld",&z);
		a[i] = z;
	}
	
	dic[0] = 1;
	
	REP(i,N){
		ans = (ppow(x,a[i]) + ans) % p;
	}
	
	PRINTLLD(ans);
	return 0;
}
0