Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34636 | 沈仲恩 | 【S】T1 | C++ | 解答错误 | 81 | 0 MS | 252 KB | 734 | 2024-11-12 13:55:08 |
#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 1e9 + 7, m2 = 500000004; inline int calc(int x) { int l = sqrt(x), r = sqrt(x) + 1; l *= l, r *= r; int mid = ((l + r) >> 1); int res = 0; if (mid < x) { res -= (mid + 1 + x) % mod * (x - mid) % mod * m2 % mod; res += mod; res %= mod; res += (l + mid) % mod * (mid - l + 1) % mod * m2 % mod; } else { res += (l + x) % mod * (x - l + 1) % mod * m2 % mod; } return (int)sqrt(l) % 2 == 0 ? -res : res; } signed main() { int l, r; scanf("%lld %lld", &l, &r); printf("%lld\n", (calc(r) - calc(l - 1) + mod) % mod); return 0; }