0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-05 02:06:27 +00:00
OI-codes/S2OJ/1238/1238.cpp

28 lines
525 B
C++
Raw Normal View History

#include <iostream>
2022-06-01 01:45:41 +00:00
#include <algorithm>
using std::cin;
using std::cout;
#define endl '\n'
int t, n, m;
long long q;
inline long long lcm(int a, int b) {
return 1ll * a * b / std::__gcd(a, b);
}
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
long long ans = 0;
cin >> n >> m >> q;
for (long long y = 0; y <= std::min(lcm(n, m) - 1, q) / m; y++) {
ans += (q - y * m) / n + 1;
}
cout << q - ans + 1 << endl;
}
return 0;
}