Iconic Arrays

Problem Statement

An iconic point in an array exists where the Kth element of the array is a multiple of K. Find the total iconic points of the array. Consider 1-based indexing for better results.

Input Format

  • The first line contains T, the number of test cases.
  • Each test case contains N, the size of the array.
  • Followed by N space-separated integers.

Output Format

  • Print the total count of iconic points of an array.

Constraints

  • 1 <= T <= 10
  • 1 <= N <= 105
  • 1 <= element <= 109
Sample Input
Sample Output

Solution

iconic_arrays.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if ((arr[i] % (i + 1)) == 0) {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Comments

Load Comments