标签:iostream span mat nbsp include int code div ==
进制
#include<iostream> #include<math.h> #define ll long long using namespace std; ll r,store[100010]; void pp(ll n) { r=0; while(n!=0){ store[r++]=n%3; n=n/3;} } int main() { ll q; cin>>q; for(int g=0;g<q;g++) { ll n,sum=0; store[100001]={0}; cin>>n; pp(n); store[r]=0; for(int i=r;i>=0;i--) { if(store[i]==2) { store[i]=0; for(int j=i+1;j<=r;j++) { if(store[j]==1) store[j]=0; else if(store[j]==0) {store[j]=1;break;} } for(int k=i;k>=0;k--) store[k]=0; break; } } for(int i=0;i<=r;i++) { sum+=store[i]*pow(3,i); } cout<<sum<<endl; } }
标签:iostream span mat nbsp include int code div ==
原文地址:https://www.cnblogs.com/hahaee/p/12080412.html