0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 16:36:28 +00:00
OI-codes/S2OJ/1238/1238.cpp

28 lines
525 B
C++

#include <iostream>
#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;
}