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 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.