結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2018-05-04 12:01:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 759 bytes |
コンパイル時間 | 488 ms |
コンパイル使用メモリ | 64,320 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 00:59:33 |
合計ジャッジ時間 | 1,119 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d %d",&x,&N); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <string> #include <vector> #include <map> using namespace std; #define INF 2000000007 #define MOD 1000003 #define MAX 105 #define REP(i,n) for(int i=0;i<(n);++i) #define REPS(i,s,t) for(int i=(s);i<(t);++i) typedef unsigned int uint; typedef unsigned long long int ull; long pow(long x, int n) { //x^n 計算量O(logn) long ans = 1; while (n > 0) { if ((n & 1) == 1) { ans = (ans * x)%MOD; } x = (x * x)%MOD; //一周する度にx, x^2, x^4, x^8となる n >>= 1; //桁をずらす n = n >> 1 } return ans; } int main(){ int x,N; scanf("%d %d",&x,&N); vector<int> a(N); REP(i,N) cin >> a[i]; uint ans = 0; for(int t : a){ ans = (ans + pow(x,t))%MOD; } cout << ans << endl; return 0; }