結果

問題 No.1680 Sum and Difference
ユーザー okok
提出日時 2021-09-17 22:25:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,141 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 08:16:06
合計ジャッジ時間 1,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD) if(n&1)ans*=x;
	return ans % MOD;
}

int solve(int A, int B){
	int res = 0;
	int i1 = (A - B) / 2, i2 = (A + B) / 2;
	
	i1 %= MOD;
	i2 %= MOD;
	A %= MOD;
	B %= MOD;
	
	res += (B + 1 + B + i1)%MOD *(i1)%MOD*power(2, MOD-2)%MOD;
	res %= MOD;
	res += (A - (i1 + 1) + A - i2)%MOD * (i2 - i1)%MOD*power(2, MOD-2)%MOD;
	res %= MOD;
	res -= (MOD-B + 1 +MOD- B + i2)%MOD * (i2 - 0)%MOD*power(2, MOD-2)%MOD;
	res += i2;
	res = (res%MOD + MOD) % MOD;
	res *= 2;
	res += B * 2 + 1;
	res %= MOD;
	
	return res;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int A, B;
	int ans = 0;
	
	cin>>A>>B;
	
	if(B > A) swap(A, B);
	
	cout<<solve(A, B)<<endl;
	
	return 0;
}
0