結果

問題 No.16 累乗の加算
ユーザー TAKEKATSUTAKEKATSU
提出日時 2019-03-24 14:51:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,117 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 162,748 KB
実行使用メモリ 10,276 KB
最終ジャッジ日時 2024-04-10 06:24:52
合計ジャッジ時間 8,023 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'long long int gcd(long long int, long long int)':
main.cpp:30:11: warning: control reaches end of non-void function [-Wreturn-type]
   30 |   else gcd(b, a%b);
      |        ~~~^~~~~~~~

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b)) * b;
}


ll calc(ll a, int x){
  
  if(a == 0)
   return 1;

  ll ans = x;
  ans %= 1000003;

  while(a != 1){
    ans *= x;
    ans %= 1000003;
    a--;
  }

  return ans;
}

int main(){

  int x, n; cin >> x >> n; 
  ll ans = 0;

  for(int i = 0; i < n; i++)
  {
    ll a; cin >> a;
    ans += calc(a, x);
  }
  pr(ans);

  return 0;
}
0