結果

問題 No.1448 和差算
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-31 20:54:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 69,644 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-21 18:34:37
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const long long mod = 1000000007;


long long modpow(long long a, long long n, long long p) {
    if (n==0) return 1LL;
    if (n&1) return modpow(a, n-1, p) * a % p;
    long long tmp = modpow(a, n/2, p);
    return tmp * tmp % p;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    long long a,b,c,d; cin >> a >> b>> c >>d;
    long long n; cin >> n;
    long long ans, x, y;

    if (n%8<4) x = b;
    else x = a;
    if (n%8<=1 || n%8>=6) y = d;
    else y = c;
    if (x<0) x+=mod;
    if (y<0) y+=mod;

    ans = modpow(16, n/8, mod);
    if (n%8==0) ans = ans*(x+y)%mod;
    else if (n%8==1) ans = ans*2*x%mod;
    else if (n%8==2) ans = ans*2*(x-y)%mod;
    else if (n%8==3) ans = ans*4*(-y)%mod;
    else if (n%8==4) ans = ans*4*(-x-y)%mod;
    else if (n%8==5) ans = ans*8*(-x)%mod;
    else if (n%8==6) ans = ans*8*(-x+y)%mod;
    else ans = ans*16%mod*y%mod;

    if (ans < 0) ans += mod;
    cout << ans << endl;
}
0