fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int int64_t
  5. #define endl '\n'
  6. #define vi vector<int>
  7. #define F0(n, i) for(int i = 0; i < n; i++)
  8. #define F1(n, i) for(int i = 1; i <= n; i++)
  9. #define each(a) for(auto& e: a)
  10.  
  11. void solve() {
  12. int n, A = 1e5;
  13. cin >> n;
  14. vi a(n), cnt(A + 1), mul(A + 1), div(A + 1);
  15. F0(n, i) {
  16. cin >> a[i];
  17. cnt[a[i]]++;
  18. }
  19. F1(A, i) {
  20. for(int j = i; j <= A; j += i) {
  21. mul[i] += cnt[j];
  22. div[j] += cnt[i];
  23. }
  24. }
  25. each(a) cout << div[e] + mul[e] - cnt[e] - 1 << ' ';
  26. }
  27.  
  28. int32_t main() {
  29. int t = 1;
  30. cin >> t;
  31. while(t--) {
  32. solve();
  33. cout << endl;
  34. }
  35. }
Success #stdin #stdout 0.02s 5612KB
stdin
3
5
6 6 6 6 6
4
1 2 3 4
5
2 3 4 5 6
stdout
4 4 4 4 4 
3 2 1 2 
2 1 1 0 2