Saleh127

UVA 11246

Dec 12th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 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.  
  11. test
  12. {
  13. ll n,a,b,c,d,e,f,i,j,k,l;
  14. cin>>n>>k;
  15. a=n;
  16. for(i=1; ;i++)
  17. {
  18. c=pow(k,i);
  19. if(c>a) break;
  20.  
  21. if(i%2)
  22. {
  23. n-=(a/c);
  24. }
  25. else n+=(a/c);
  26. }
  27. cout<<n<<endl;
  28.  
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment