题解:P12441 [NERC2023] Joy of Pokémon Observation
Priestess_SLG · · 题解
先特判
inline void sol() {
int t, s; cin >> t >> s;
if (s == 1) {
int x; cin >> x;
cout << ((t % x) ? 0 : 1) << '\n';
} else if (s == 2) {
int x, y, res = 0; cin >> x >> y;
int LCM = lcm(x, y), cnt = 0;
for (int i = 0; i < LCM / y; ++i)
if (t >= i * y) {
int d = (t - i * y) % LCM;
if (d % x == 0) cnt += (t - i * y) / LCM + 1;
}
cout << cnt << '\n';
} else {
int x, y, z; cin >> x >> y >> z;
int LCM = lcm(lcm(x, y), z), cnt = 0;
for (int i = 0; i < LCM / z; ++i)
for (int j = 0; j < LCM / y; ++j)
if (t >= i * z + j * y) {
int d = (t - i * z - j * y) % LCM;
if (d % x == 0) cnt += ((t - i * z - j * y) / LCM + 1) * ((t - i * z - j * y) / LCM + 2) / 2;
}
cout << cnt << '\n';
}
}