fork download
  1. #include<iostream>
  2. #include<vector>
  3. #include<math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. std::ios::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. int n,i,q,k,j,flag,res,temp;
  12. cin>>n;
  13. int a[100000],fact[100001]={0};
  14.  
  15. for(i=0;i<n+1;i++)
  16. {
  17. fact[i]=0;
  18. }
  19.  
  20. for(i=0;i<n;i++)
  21. {
  22. cin>>a[i];
  23. fact[a[i]]++;
  24. for(j=2;j<=sqrt(a[i]);j++)
  25. {
  26. if(a[i]%j==0)
  27. {
  28. fact[j]++;
  29. if(a[i]/j!=j)
  30. fact[a[i]/j]++;
  31. }
  32. }
  33. }
  34. fact[1]=n;
  35. cin>>q;
  36. for(i=0;i<q;i++)
  37. {
  38. cin>>k;
  39. cout<<fact[k]<<endl;
  40. }
  41. }
Success #stdin #stdout 0s 16728KB
stdin
10
1
3
5
7
9
2
4
6
8
20
5
1
2
3
4
5
stdout
10
5
3
3
2