結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2018-05-09 10:23:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,175 bytes |
コンパイル時間 | 1,945 ms |
コンパイル使用メモリ | 174,976 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-28 02:38:57 |
合計ジャッジ時間 | 2,529 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
#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 secondusing 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;}