Advertisement
Guest User

Represent "N" with "k"

a guest
Mar 31st, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6. ll n,k;
  7. cin>>n>>k;
  8. ll x=n;
  9. ll a[101]={0};
  10. ll index=0;
  11. /// this section is the main algo
  12. while(n)
  13. {
  14. ll reminder=n%k;
  15. n=n/k;
  16. a[index]+=reminder;
  17. index++;
  18. }
  19. /// this section is used to print values
  20. for(int i=0;i<101;i++)
  21. {
  22. if(a[i]!=0)
  23. {
  24. for(int j=0;j<a[i];j++)
  25. cout<<k<<"^"<<i<<" + ";
  26. }
  27. }
  28. cout<<"0 = "<<x;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement