水题,注意到 l,r,x均特别小,直接枚举 x 的倍数,暴力即可。
#include<bits/stdc++.h>
using i64 = long long;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int l, r, x;
std::cin >> l >> r >> x;
int z = x;
while (z <= r) {
if (z >= l && z <= r) {
std::cout << z;
return 0;
}
z += x;
}
std::cout << -1;
return 0;
}

京公网安备 11010502036488号