Advertisement
konchin_shih

TOPC pH C++進制轉換解

Oct 28th, 2022
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. using ll=long long;
  6. template<typename T> using V=vector<T>;
  7. constexpr ll base=6ll*6*6*6*6*6*6*6*6*6*6*6;
  8. constexpr ll N=1000000000;
  9. static inline void solve(){
  10.     string str;cin>>str;
  11.     if(str=="0"){
  12.         cout<<1<<endl;
  13.         return;
  14.     }
  15.     V<ll> num;
  16.     while(str.size()>=9){
  17.         num.emplace_back(atoll(str.substr(str.size()-9).data()));
  18.         str.resize(str.size()-9);
  19.     }
  20.     if(str.size())
  21.         num.emplace_back(atoll(str.data()));
  22.     reverse(num.begin(),num.end());
  23.     V<ll> res{0};
  24.     for(auto& x:num){
  25.         ll cur=x;
  26.         for(auto& i:res)
  27.             cur+=i*N,i=cur%base,cur/=base;
  28.         if(cur)
  29.             res.emplace_back(cur);
  30.     }
  31.     int ans=12*(res.size()-1);
  32.     while(res.back()>0)
  33.         ans++,res.back()/=6;
  34.     cout<<ans<<endl;
  35. }
  36. signed main(){
  37.     int T=1;
  38.     //cin>>T;
  39.     while(T--)
  40.         solve();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement