結果

問題 No.1448 和差算
ユーザー rogi52
提出日時 2022-10-07 21:14:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 3,741 ms
コンパイル使用メモリ 195,468 KB
最終ジャッジ日時 2025-02-07 22:44:06
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll mod = 1e9+7;
ll modpow(ll a,ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll A,B,C,D,N; cin >> A >> B >> C >> D >> N;
    auto f = [N](ll a, ll b) {
        rep(_,N%8) tie(a, b) = make_pair(a - b, a + b);
        return a + b;
    };

    ll ans = max({f(A, C), f(A, D), f(B, C), f(B, D)});
    ans = (ans % mod + mod) % mod;
    ans *= modpow(16, N / 8);
    ans %= mod;
    cout << ans << endl;
}
0