fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. long long k,a[100000 + 5];
  8. cin>>n>>k;
  9. for(int i = 1; i <= n;i ++)cin>>a[i];
  10.  
  11. vector <int> uoc;
  12. // co the dung mang khai bao sang cx dc vd : uoc[10005] neu ko quen dung vector
  13.  
  14. // doan nay de tim uoc cua k
  15. for(int i = 1; i <= k; i ++)if(k % i == 0)uoc.push_back(i);
  16.  
  17. int f[100000 + 5];
  18. //f[i] la so luong cac phan tu trong mang a chia het cho i
  19.  
  20. long long ans = 0;
  21. for(int i = 1; i <= n;i ++)
  22. {
  23. int need = 0;
  24.  
  25. for(int u : uoc)
  26. {
  27. long long so = a[i] * u;
  28. if(so % k == 0){need = u;break;}
  29. }
  30.  
  31. ans += (long long)f[need];
  32.  
  33. for(int u : uoc)
  34. {
  35. if(a[i] % u == 0)f[u] ++;
  36. }
  37. }
  38. cout<<ans;
  39.  
  40. return 0 ;
  41. }
  42.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty