T1:
链接:https://www.luogu.org/problem/P2520
$sol:$数学推导(咕
代码:
#include <bits/stdc++.h> typedef int intt; #define int long long using namespace std; int a, b, x, y, t, d; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } bool check(int x, int y) { return (x % d == 0 && y % d == 0) || ((x + a) % d == 0 && (y + b) % d == 0) || ((x + b) % d == 0 && (y + a) % d == 0) || ((x + a + b) % d == 0 && (y + a + b) % d == 0); } intt main() { cin >> t; while(t--) { cin >> a >> b >> x >> y; d = gcd(a, b) << 1; check(x, y) ? (cout << "Y" << endl) : (cout << "N" << endl); } return 0; }
T2:
链接:https://www.luogu.org/problem/P4626
$sol$:欧拉筛处理出范围内的素数,用素数的最高次幂来表示即可达到最终结果。此题卡空间卡常,需要使用$bitset$等技巧优化。
代码:
// luogu-judger-enable-o2 #include <cstdio> #include <bitset> #include <iostream> const int MAXN = 100000005; const int mod = 100000007; typedef long long ll; using namespace std; bitset<MAXN> vis; int n, cnt, prime[10000005]; ll ans = 1; void get_prime() { for(register int i = 2; i <= n; i++) { if(!vis[i]) prime[++cnt] = i; for(register int j = 1; i * prime[j] <= n && j <= cnt; j++) { vis[i * prime[j]] = 1; if(i % prime[j] == 0) break; } } } ll calc(int x) { ll ans = x; while(ans <= n) ans = ans * x; return ans / x % mod; } int main() { ios::sync_with_stdio(false); cin >> n; get_prime(); for(int i = 1; i <= cnt; i++) ans = (ans * calc(prime[i]) % mod) % mod; cout << ans % mod << endl; return 0; }
T3:
链接:https://www.luogu.org/problem/P1516
$sol$:解不定方程,最后要注意解的范围。
代码:
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll x, y, m, n, l; ll exgcd(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll gcd = exgcd(b, a % b, x, y); ll t = x; x = y; y = t - a / b * y; return gcd; } int main() { cin >> x >> y >> m >> n >> l; ll a = n - m, c = x - y; if(a < 0) { a *= -1; c *= -1; } ll gcd = exgcd(a, l, x, y); if(c % gcd != 0) { cout << "Impossible" << endl; return 0; } l /= gcd; cout << (x * (c / gcd) % l + l) % l << endl; return 0; }