fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define all(x) x.begin(), x.end()
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace __gnu_pbds;
  9. template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  10. template <typename T, typename R> using o_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  11. typedef long long ll;
  12.  
  13. #define inf 1e9
  14. #define MOD 1000000007
  15. #define vint vector<int>
  16. #define vll vector<ll>
  17. #define no cout << "NO" << endl;
  18.  
  19. void solve() {
  20. ll x , y , k ; cin >> x >> y >> k ;
  21. ll z = y * (x /y +1 ) ;
  22. cout << z << endl ;
  23. if (z - x >k ) {
  24. cout << x + k << endl ; return;
  25. }
  26.  
  27. k-=( z -x ) ;
  28. cout << k << endl ;
  29. while (z % y == 0 ) {
  30. z/= y ;
  31. }
  32. cout << z << endl ;
  33. if ( y - z > k ) {
  34. cout << z + k << endl ; return;
  35. }
  36. k-= (y-z ) ;
  37. cout << k % (y-1)+1 << endl ;
  38.  
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45. int main() {
  46. ios::sync_with_stdio(false);
  47. cin.tie(nullptr);
  48.  
  49. #ifndef ONLINE_JUDGE
  50. freopen("input.txt", "r", stdin);
  51. freopen("output.txt", "w", stdout);
  52. #endif
  53.  
  54.  
  55. int t = 1 ;
  56. cin >> t;
  57. while (t--) {
  58. solve();
  59. }
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
-5945102217976862208
5945102217976862209
1
-611437419778964988