Untitled
user_5668965
c_cpp
a year ago
776 B
8
Indexable
#include <bits/stdc++.h> using i64 = long long; void solve() { int n; std::cin >> n; std::vector<int> a(n), b(n); for (int i = 0; i < n; i++) { std::cin >> a[i] >> b[i]; } i64 g = 0, m = 1; int ans = 1; for (int i = 0; i < n; i++) { if (std::gcd(g, 1LL * a[i] * b[i]) % std::lcm(m, 1LL * b[i]) != 0) { ans += 1; g = 0; m = 1; } g = std::gcd(g, 1LL * a[i] * b[i]); m = std::lcm(m, 1LL * b[i]); } std::cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }
Editor is loading...
Leave a Comment