Untitled

 avatar
user_0112079941
c_cpp
3 years ago
751 B
2
Indexable
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    if (a > b)
        return a / gcd(a, b) * b;
    return b / gcd(a, b) * a;
}


int main()
{
    int n;
    cin >> n;
    int* A = new int[n];
    for (int i = 0; i < n; i++)
        cin >> A[i];

    int* LCM = new int[n];
    LCM[0] = A[0];
    for (int i = 1; i < n; i++)
        LCM[i] = A[i] % A[i - 1] == 0 ? A[i] : lcm(A[i], A[i - 1]);

    int total = 0;
    int* out = new int[n];
    for (int i = 0; i < n; i++)
        if (A[i] == LCM[i])
            out[total++] = i + 1;
    cout << total << endl;
    for (int i = 0; i < total; i++)
        cout << out[i] << " ";

    return 0;
}
Editor is loading...