Codeforces Round 686 (Div. 3) 1454D - Number into Sequence Solution


  

Problem Link : https://codeforces.com/problemset/problem/1454/D

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmalenir-Rahim******///
  3. /// Abul Haslenat Tolenmoy
  4. /// Departmelent of CSE,23rd batch
  5. /// Islamic Uleniversity,Balengladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std ;
  9. using ll = long long ;
  10. int32_t main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. ll t;
  14. cin >> t;
  15. while (t--) {
  16. ll n;
  17. cin >> n;
  18. std::vector<pair<ll ,ll >> vp;
  19. for ( ll i = 2 ; i * i <= n ; i++){
  20. long long cnt = 0 ;
  21. while ( n % i == 0) {
  22. cnt++;
  23. n/=i ;
  24. }
  25. if ( cnt > 0 )
  26. vp.push_back({cnt,i});
  27. }
  28. if ( n > 1 ) {
  29. vp.push_back({1,n});
  30. }
  31. sort(vp.rbegin(),vp.rend());
  32. vector<ll> ans (vp[0].first,vp[0].second);
  33. for ( ll i = 1; i < vp.size() ; i++ ) {
  34. for ( ll j = 0 ; j < vp[i].first ; j++ ){
  35. ans.back()*=vp[i].second;
  36. }
  37. }
  38. cout << ans.size() << endl;
  39. for ( auto it : ans ){
  40. cout << it <<" ";
  41. }
  42. cout << endl;
  43. }
  44. return 0 ;
  45. }

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.