Maruf_Hasan

C2

Oct 23rd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main()
  6. {
  7. ll n;
  8. cin>>n;
  9. string a;
  10.  
  11. ll num=0;
  12.  
  13. int mx=ceil((double)log(n)/log(3));
  14. //cout<<mx<<endl;
  15. for(int i=0; i<=mx; i++)
  16. {
  17. a.push_back('1');
  18. }
  19.  
  20. for(int i=0; i<=mx; i++)
  21. {
  22. // if(a[i]=='1')
  23. num+=pow(3,i);
  24. }
  25. //cout<<num<<endl;
  26. ll ans;
  27. for(int i=mx;i>=0; i--)
  28. {
  29. ll x=pow(3,i);
  30. if(num-x>=n)
  31. {
  32. a[i]='0';
  33. num=num-x;
  34. // cout<<num<<endl;
  35. }
  36. }
  37. ll w=0;
  38. for(int i=0;i<a.size();i++)
  39. {
  40. if(a[i]=='1')
  41. w+=pow(3,i);
  42. }
  43. cout<<w<<endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment