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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.