constint MAXN = 1E5 + 5; constint MOD = 1E9 + 7; int n, m, q; vector<int> G[MAXN]; vector<pair<int, int>> city[MAXN]; array<int, MAXN> in, a, b, s, t, p[22];
voiddfs(int now){ for (auto& to : G[now]) { for (int j = 1; j <= 20; j++) if (p[j - 1][to]) p[j][to] = p[j - 1][p[j - 1][to]]; dfs(to); } }
signedmain(){ read(n, m, q); for (int i = 1; i <= m; i++) { read(a[i], b[i], s[i], t[i]); city[a[i]].push_back({s[i], i}); } for (int i = 1; i <= n; i++) sort(city[i].begin(), city[i].end()); for (int i = 1; i <= n; i++) { for (auto& [s, j] : city[i]) { auto it = lower_bound(city[b[j]].begin(), city[b[j]].end(), make_pair(t[j], 0)); if (it != city[b[j]].end()) { G[it->second].push_back(j); p[0][j] = it->second; in[j]++; } } } for (int i = 1; i <= m; i++) if (!in[i]) dfs(i); for (int i = 1; i <= q; i++) { int x, y, z; read(x, y, z); auto it = lower_bound(city[y].begin(), city[y].end(), make_pair(x, 0)); if (it == city[y].end()) printf("%d\n", y); else { int bus = it->second; if (z <= s[bus]) printf("%d\n", y); else { for (int j = 20; ~j; j--) if (p[j][bus] && s[p[j][bus]] < z) bus = p[j][bus]; if (z <= t[bus]) printf("%d %d\n", a[bus], b[bus]); else printf("%d\n", b[bus]); } } } return0; }
LL qpow(LL a, LL b, LL MOD){ LL ans = 1, base = a % MOD; while (b) { if (b & 1) ans = ans * base % MOD; b >>= 1, base = base * base % MOD; } return ans; }
signedmain(){ cin >> p; p--; for (int i = 1; i <= sqrt(p); i++) { if (p % i == 0) { fac.push_back(i); if (p / i != i) fac.push_back(p / i); } } sort(fac.begin(), fac.end()); for (int i = fac.size() - 1; ~i; i--) { (f[fac[i]] += p / fac[i]) %= MOD; for (int j = i - 1; ~j; j--) if (fac[i] % fac[j] == 0) (f[fac[j]] -= f[fac[i]]) %= MOD; } LL ans = 0; for (auto& v : fac) { ans += p % MOD * qpow(v, MOD - 2, MOD) % MOD * f[v] % MOD; ans %= MOD; } cout << (ans + 1 + MOD) % MOD; return0; }
#define int long long constint MAXN = 2E5 + 5; constint MOD = 998244353; int n, k; int c[MAXN];
LL qpow(LL a, LL b, LL MOD){ LL ans = 1, base = a % MOD; while (b) { if (b & 1) ans = ans * base % MOD; b >>= 1, base = base * base % MOD; } return ans; }
voidFWT_XOR(int* A, int N, int tag){ for (int sz = 1; sz < N; sz *= 2) for (int i = 0; i < N; i += sz * 2) for (int k = 0; k < sz; k++) { constint x = A[i + k], y = A[i + k + sz]; A[i + k] = (x + y) % MOD; A[i + k + sz] = (x - y) % MOD; } if (tag == -1) for (int i = 0; i < N; i++) (A[i] *= qpow(N, MOD - 2, MOD)) %= MOD; }
signedmain(){ ios::sync_with_stdio(false); cin >> n >> k; int N = (1 << 16); for (int i = 1, x; i <= k; i++) cin >> x, c[x] = 1; FWT_XOR(c, N, 1); for (int i = 0; i < N; i++) { if (c[i] == 1) c[i] = n; else c[i] = c[i] * (1 - qpow(c[i], n, MOD)) % MOD * qpow(1 - c[i], MOD - 2, MOD) % MOD; } FWT_XOR(c, N, -1); int ans = 0; for (int i = 1; i < N; i++) ans = (ans + c[i]) % MOD; cout << (ans + MOD) % MOD; return0; }