結果
問題 | No.1680 Sum and Difference |
ユーザー |
|
提出日時 | 2021-10-13 13:49:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 618 bytes |
コンパイル時間 | 557 ms |
コンパイル使用メモリ | 65,948 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 16:16:47 |
合計ジャッジ時間 | 1,354 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; const long long md = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a, b; cin >> a >> b; if (a > b) swap(a, b); long long ans = 0; if ((b - a) & 1) ans = ((a * 2 + 1LL) % md) * ((b - a) % md); else ans = ((a * 2 + 1LL) % md) * ((b - a + 1LL) % md); if ((b - a) & 1) a = a * 2; else a = a * 2 - 1LL; if (a > 0) { if (a & 1) ans += (((a + 1LL) / 2) % md) * (((a + 1LL) / 2) % md) * 2LL; else ans += (((a + 1LL) / 2) % md) * (((a + 1LL) / 2 + 1LL) % md) * 2LL; } ans %= md; cout << ans << '\n'; return 0; }