Untitled
unknown
plain_text
12 days ago
643 B
2
Indexable
class Solution { public: int flag=0; void compute(vector<int>&v,int n) { for(auto it:v)cout<<it<<" "; cout<<endl; long long a=0,k=0; for(int i=v.size()-1;i>=0;i--) { a+=(v[i]*pow(3,k++)*1ll); } if(a<100)cout<<a<<" "; if(a==n) { flag=1; } } void solve(int i,vector<int>&v,int n) { if(i>=v.size()) { compute(v,n); return ; } solve(i+1,v,n); v[i]=1; solve(i+1,v,n); } bool checkPowersOfThree(int n) { vector<int>v(17,0); solve(0,v,n); if(flag)return true; return false; } };
Editor is loading...
Leave a Comment