1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; const int N = 5e4 + 10, mod = 1e9 + 7; int n, m; int cnt; LL p[N], low[N], phi[N], sphi[N]; void init() { phi[1] = 1; low[1] = 1; for (int i = 1; i < N; i++) { if (!low[i]) { p[++cnt] = i; phi[i] = i - 1; low[i] = i; } for (int j = 1; j <= cnt && i * p[j] < N; j++) { if (i % p[j] == 0) { if (low[i] == i) phi[i * p[j]] = phi[i] * p[j]; else phi[i * p[j]] = phi[i / low[i]] * phi[p[j] * low[i]]; low[i * p[j]] = low[i] * p[j]; break; } phi[i * p[j]] = phi[i] * phi[p[j]]; low[i * p[j]] = p[j]; } } for (int i = 1; i < N; i++) sphi[i] = (sphi[i - 1] + phi[i]) % mod; } LL f(int a, int b) { LL res = 0; for (int l = 1, r; l <= min(a, b); l = r + 1) { r = min(a / (a / l), b / (b / l)); res += (sphi[r] - sphi[l - 1]) * (LL)(a / l) * (LL)(b / l); } return res; } int main() { init(); int T; scanf("%d%d%d", &T, &n, &m); for (int a, b, c, d; T; T--) { scanf("%d%d%d%d", &a, &b, &c, &d); printf("%lld\n", (f(c, d) - f(a - 1, d) - f(b - 1, c) + f(a - 1, b - 1)) % mod); } return 0; }
|