The issue is here:
for(int j=2;j<=a[i];j++){
if(a[i]%j==0&&prime[j]==true){
m[j]++;
f=1;
}
}
Length of prime[]
is 10^4, whereas A_i can be as as big as 10^9. j
should be less than length of prime. You are accessing out of bounds memory.