結果

問題 No.1343 Dividing Digit
ユーザー hayatenhayaten
提出日時 2021-01-16 13:11:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 200,580 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 09:19:06
合計ジャッジ時間 3,736 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 54 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 15 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 43 ms
4,384 KB
testcase_09 AC 48 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 39 ms
4,376 KB
testcase_13 AC 36 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 48 ms
4,380 KB
testcase_18 AC 53 ms
4,376 KB
testcase_19 AC 35 ms
4,380 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 46 ms
4,376 KB
testcase_22 AC 45 ms
4,380 KB
testcase_23 AC 57 ms
4,376 KB
testcase_24 AC 48 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
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 dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  ll mod = 0;
  rep(i, n) mod += A[i];
  ll ans = 0;
  reverse(ALL(A));
  rep(i, n){
    ans += modpow(k, i, mod) * A[i];
    ans %= mod;
  }
  cout << ans << endl;
}
0