Codeforces Gym 310911G Solution



 Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int N = 1e6 + 5 ;
  5. const int M = 1e6 ;
  6. int cnt[N] , mul[N] ;
  7. int32_t main() {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. int n ;
  11. cin >> n ;
  12. for ( int i = 1 ; i <= n ; i++) {
  13. int x ;
  14. cin >> x ;
  15. cnt[x]++ ;
  16. }
  17. for ( int i = 1 ; i < N ; i++) {
  18. for ( int j = i ; j < N ; j+=i ){
  19. mul[i] += cnt[j] ;
  20. }
  21. }
  22. for ( int i = 1 ; i <= M ; i++){
  23. cout << mul[i] <<" ";
  24. }
  25. cout <<"\n";
  26. return 0 ;
  27. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.