結果

問題 No.1448 和差算
ユーザー LiesegangLiesegang
提出日時 2021-04-03 01:24:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,047 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 198,944 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 15:54:21
合計ジャッジ時間 5,320 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void pow(ll a, ll b, ll c, ll d, ll i, ll &ra, ll &rb, ll &rc, ll &rd)
{
  while(i){
    if (i & 1) {
      ll ta = ra * a + rb * c;
      ll tb = ra * b + rb * d;
      ll tc = rc * a + rd * c;
      ll td = rc * b + rd * d;
      ra = ta; rb = tb; rc = tc; rd = td;
    }
    ll ta = a * a + b * c;
    ll tb = a * b + b * d;
    ll tc = a * c + c * d;
    ll td = b * c + d * d;
    a = ta; b = tb; c = tc; d = td;
    i >>= 1;
  }
  return;
}

const ll mod = 1000000000 + 7;

int main() {
  ll a, b, c, d, n;
  cin >> a >> b >> c >> d >> n;
  ll ra = 1, rb = 0, rc = 0, rd = 1;
  pow(1, -1, 1, 1, n, ra, rb, rc, rd);

  ra += rc;
  rb += rd;
  if (ra >= 0)
  {
    ra %= mod;
    ra *= b;
    ra %= mod;
  }
  else
  {
    ra %= mod;
    ra *= a;
    ra %= mod;
  }

  if(rb >= 0) {
    rb %= mod;
    rb *= d;
    rb %= mod;
  } else {
    rb %= mod;
    rb *= c;
    rb %= mod;
  }
  ra += mod;
  ra %= mod;
  rb += mod;
  rb %= mod;

  cout << (ra + rb) % mod << endl;
}
0