Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("decbin.in");
- ofstream cout("decbin.out");
- int n,b,i,aux,nr,j,ok,r;
- long long p,put,maxx,v[100005];
- void citire()
- {
- cin>>n>>b;
- }
- void rezolvare()
- {
- aux=n;
- while(aux)
- {
- nr++;
- aux=aux/b;
- }
- p=1<<nr;
- p--;
- cout<<0<<'\n';
- ok=1;
- i++;
- nr=0;
- while(i<=p && ok==1)
- {
- r=1;
- for(j=1; j<=nr && r==1; j++)
- {
- v[j]=v[j]+r;
- if(v[j]==2){
- v[j]=0;
- r=1;
- }
- if(v[j]==1)
- {
- r=0;
- }
- }
- if(r>0)
- {
- v[++nr]=1;
- r=0;
- }
- /*for(j=nr; j>=1; j--)
- {
- cout<<v[j];
- }
- cout<<' ';*/
- put=1;
- maxx=0;
- for(j=1; j<=nr; j++)
- {
- maxx=put*v[j]+maxx;
- put=put*b;
- }
- if(maxx>n)
- ok=0;
- else cout<<maxx<<'\n';
- i++;
- }
- }
- int main()
- {
- citire();
- rezolvare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement