結果

問題 No.1448 和差算
ユーザー 夜
提出日時 2021-03-31 19:10:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 91,848 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 17:09:17
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 1000000007;
long long m_pow(long long x, long long y) {
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
int main() {
	long long a, b, c, d, n;
	cin >> a >> b >> c >> d >> n;
	long long ans = 0;
	if (n % 8 == 0) {
		long long p = m_pow(2, n / 2);
		ans += p * b;
		ans %= mod;
		ans += p * d;
		ans %= mod;
	}
	if (n % 8 == 1) {
		long long p = m_pow(2, (n + 1) / 2);
		ans += p * b;
		ans %= mod;
	}
	if (n % 8 == 2) {
		long long p = m_pow(2, n / 2);
		ans += p * b;
		ans %= mod;
		ans += -p * c;
		ans %= mod;
	}
	if (n % 8 == 3) {
		long long p = m_pow(2, (n + 1) / 2);
		ans += -p * c;
		ans %= mod;
	}
	if (n % 8 == 4) {
		long long p = m_pow(2, n / 2);
		ans += -p * a;
		ans %= mod;
		ans += -p * c;
		ans %= mod;
	}
	if (n % 8 == 5) {
		long long p = m_pow(2, (n + 1) / 2);
		ans += -p * a;
		ans %= mod;
	}
	if (n % 8 == 6) {
		long long p = m_pow(2, n / 2);
		ans += -p * a;
		ans %= mod;
		ans += p * d;
		ans %= mod;
	}
	if (n % 8 == 7) {
		long long p = m_pow(2, (n + 1) / 2);
		ans += p * d;
		ans %= mod;
	}
	cout << (ans+mod)%mod << endl;
}
0