Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void getDivisor(vector<int> &v, int n) {
- for (int i = 1; i < int((n / 2) + 1); i++) {
- if (!(n % i))
- v.push_back(i);
- }
- v.push_back(n);
- }
- void getCommon(vector<int> &v1, vector<int> &v2, vector<int> &ret) {
- for (int x : v1) {
- for (int y : v2) {
- if (x == y)
- ret.push_back(x);
- }
- }
- }
- void showVec(vector<int> &v) {
- for (int x : v) {
- cout << x << '\n';
- }
- }
- int main() {
- int n;
- int r[3];
- cin >> n;
- for (int i = 0; i < n; i++) {
- int m;
- cin >> m;
- r[i] = m;
- }
- vector<int> div[3];
- for (int i = 0; i < n; i++) {
- getDivisor(div[i], r[i]);
- }
- vector<int> ret[2];
- getCommon(div[0], div[1], ret[0]);
- if (n == 3) {
- getCommon(div[2], ret[0], ret[1]);
- }
- if (n == 2) {
- showVec(ret[0]);
- } else {
- showVec(ret[1]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment