Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
35009 | 沈仲恩 | 【S】T1 | C++ | 通过 | 100 | 0 MS | 256 KB | 918 | 2024-11-21 14:50:54 |
#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 1e9 + 7; inline int ksm(int x, int y) { y %= mod - 1; int res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod, y >>= 1; } return res; } signed main() { // freopen("bala.in", "r", stdin); // freopen("bala.out", "w", stdout); int l, r; scanf("%lld %lld", &l, &r); // 2^{r+1} - 2^l int k = (ksm(2, r + 1) - ksm(2, l) + mod) % mod; int c = 0; if (l & 1) { if (r & 1) c = (r - l) / 2 * 3 + 2; else c = (r - l + 1) / 2 * 3; } else { if (r & 1) c = (r - l + 1) / 2 * 3; else c = (r - l) / 2 * 3 + 1; } c %= mod; printf("%lld\n", (k - c + mod) % mod * ksm(3, mod - 2) % mod); return 0; }