結果

問題 No.2111 Sum of Diff
ユーザー chro_96chro_96
提出日時 2022-10-28 21:43:54
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 00:49:35
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;
  
  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * a) % mod_num;
    }
  }
  
  return ans;
}

int main () {
  int n = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long a = 0LL;
    res = scanf("%lld", &a);
    ans += (a*power_mod(2LL, (long long)(n-i-1), mod_num))%mod_num;
    ans += mod_num-(a*power_mod(2LL, (long long)i, mod_num))%mod_num;
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0