Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC diagnostic ignored "-Wunused-result"
- #include <bits/stdc++.h>
- typedef long long Int;
- Int gcd(Int a, Int b) {
- return b == 0 ? a : gcd(b, a % b);
- }
- bool is_finite(Int p, Int q, Int b) {
- if (p == 0) {
- return true;
- }
- Int d = ::gcd(p, q);
- p /= d;
- q /= d;
- if (q == 1) {
- return true;
- }
- p %= q;
- b %= q;
- return gcd(b, q) == 1 ? false : true;
- }
- int main() {
- std::ios_base::sync_with_stdio(false);
- std::cin.tie(0); std::cout.tie(0);
- int nQueries;
- std::cin >> nQueries;
- while (nQueries--) {
- Int p, q, b; std::cin >> p >> q >> b;
- std::cout << (is_finite(p, q, b) ? "Finite" : "Infinite") << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement