Advertisement
Saleh127

UVA 10551

Nov 15th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll d,e,f,n,num,i,j,base,l;
  11. string a,b;
  12.  
  13. while(cin>>n &&n)
  14. {
  15. cin>>a>>b;
  16. l=b.size();
  17. num=0;
  18. base=1;
  19. for(i=l-1;i>=0;i--)
  20. {
  21. num+=(b[i]-'0')*base;
  22. base*=n;
  23. }
  24. base=0;
  25. for(i=0;i<a.size();i++)
  26. {
  27. base=(a[i]-'0')+(base*n);
  28. base%=num;
  29. }
  30. ll ans[1000],j=-1;
  31. while(base)
  32. {
  33. ans[++j]=base%n;
  34. base/=n;
  35. }
  36. for(i=j;i>=0;i--)
  37. {
  38. cout<<ans[i];
  39. }
  40. if(j==-1) cout<<0;
  41. cout<<endl;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement