結果

問題 No.1448 和差算
ユーザー tktk_snsn
提出日時 2021-03-31 20:49:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 69,752 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-15 08:09:27
合計ジャッジ時間 1,496 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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;

    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*y%mod;

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