結果
問題 | No.1448 和差算 |
ユーザー |
![]() |
提出日時 | 2021-03-31 20:54:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 599 ms |
コンパイル使用メモリ | 70,480 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-15 08:15:41 |
合計ジャッジ時間 | 1,869 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#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; }