Advertisement
erfanul007

UVa 11313

Mar 23rd, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--){
  9. int n,k,mod,mul,cnt=0;
  10. cin>>n>>k;
  11. while(n>=k){
  12. mod=n%k;
  13. mul=n/k;
  14. n=mul;
  15. n+=mod;
  16. cnt+=mul;
  17.  
  18. }
  19. if(n==1){
  20. cout<<cnt<<endl;
  21. }
  22. else{
  23. cout<<"cannot do this"<<endl;
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement