Looks like I was wrong somewhere that made the program not run.
The input consists of a count and then that many numbers; the output is the number of divisors (including 1 and itself) for each element of the array.
Sample:
input 3 16 17 18
output 5 2 6
Code:
#include <bits/stdc++.h>
using namespace std;
int countDivisors(int a[], int n) {
int cnt = 0;
for(int j = 1; j <= sqrt(a[i]); j++) {
if(a[i] % j == 0) {
if(a[i] % j == j) {
cnt++;
}
else {
cnt = cnt + 2;
}
}
}
return cnt;
}
int main() {
int n, i = 0;
cin >> n;
int a[n];
for(;i < n; i++) {
cin >> a[i];
}
cout << " " << countDivisors(a, n);
return 0;
}