mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-14 05:58:47 +00:00
28 lines
525 B
C++
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;
|
|
}
|