#include <bits/stdc++.h> #define nwd(a, b) __gcd(a, b) #define nww(a, b) (a * b) / (nwd(a, b)) using namespace std; int n, res = 1, amt, temp; int main() { cin.sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; ++i) { cin >> amt; for(int j = 0; j < amt; ++j) cin >> temp; if(amt == 0 && i == 1) { res == -1; } if(amt != 0 && res != -1) res = nww(res, amt); } if(res == -1) cout << 1; else cout << res; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <bits/stdc++.h> #define nwd(a, b) __gcd(a, b) #define nww(a, b) (a * b) / (nwd(a, b)) using namespace std; int n, res = 1, amt, temp; int main() { cin.sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; ++i) { cin >> amt; for(int j = 0; j < amt; ++j) cin >> temp; if(amt == 0 && i == 1) { res == -1; } if(amt != 0 && res != -1) res = nww(res, amt); } if(res == -1) cout << 1; else cout << res; } |