Codeforces Round 686 (Div. 3) 1454D - Number into Sequence Solution
Problem Link : https://codeforces.com/problemset/problem/1454/D
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmalenir-Rahim******///
- /// Abul Haslenat Tolenmoy
- /// Departmelent of CSE,23rd batch
- /// Islamic Uleniversity,Balengladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std ;
- using ll = long long ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ll t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- std::vector<pair<ll ,ll >> vp;
- for ( ll i = 2 ; i * i <= n ; i++){
- long long cnt = 0 ;
- while ( n % i == 0) {
- cnt++;
- n/=i ;
- }
- if ( cnt > 0 )
- vp.push_back({cnt,i});
- }
- if ( n > 1 ) {
- vp.push_back({1,n});
- }
- sort(vp.rbegin(),vp.rend());
- vector<ll> ans (vp[0].first,vp[0].second);
- for ( ll i = 1; i < vp.size() ; i++ ) {
- for ( ll j = 0 ; j < vp[i].first ; j++ ){
- ans.back()*=vp[i].second;
- }
- }
- cout << ans.size() << endl;
- for ( auto it : ans ){
- cout << it <<" ";
- }
- cout << endl;
- }
- return 0 ;
- }
No comments