What's wrong in this code

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

int main() {
int n;
cin >> n;

int a[n];

int cnt[100005] = {0};

for(int i = 0; i < n; i++) {
	cin >> a[i];
	cnt[a[i]]++;
}

int sum[100005] = {0};
for(int i = 2; i <= 100005; i++) {
	for(int j = i; j <= 100005; j += i) {
		sum[i] += cnt[j];
	}
}

int q;
cin >> q;

while(q--) {
	int a;
	cin >> a;
	
	cout << sum[a] << endl;
}

}

Hey saurav what if k=1 i have commented your mistake ->


input:
4
5 8 10 8
1
1
For this ans should be 4 but your code gives 0

Hope this resolved your doubt.
Remember to mark it as resolved in my doubts
section :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.