Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- ll n;
- cin>>n;
- string a;
- ll num=0;
- int mx=ceil((double)log(n)/log(3));
- //cout<<mx<<endl;
- for(int i=0; i<=mx; i++)
- {
- a.push_back('1');
- }
- for(int i=0; i<=mx; i++)
- {
- // if(a[i]=='1')
- num+=pow(3,i);
- }
- //cout<<num<<endl;
- ll ans;
- for(int i=mx;i>=0; i--)
- {
- ll x=pow(3,i);
- if(num-x>=n)
- {
- a[i]='0';
- num=num-x;
- // cout<<num<<endl;
- }
- }
- ll w=0;
- for(int i=0;i<a.size();i++)
- {
- if(a[i]=='1')
- w+=pow(3,i);
- }
- cout<<w<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment