fork(3) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin >> t;
  9.  
  10. for (int i = 0; i < t; i++)
  11. {
  12. int rem = 0, n, m, count = 0;
  13. cin >> n >> m;
  14.  
  15. for(int q = 0; q < n; q++)
  16. {
  17. int nodeatm = pow(2,q) + rem;
  18. if( nodeatm < m)
  19. {
  20. count++;
  21. rem = 0;
  22. }
  23. else
  24. {
  25. count += ( nodeatm/ m );
  26. rem = ( nodeatm % m );
  27. }
  28.  
  29. }
  30.  
  31. if( rem )
  32. count++;
  33.  
  34. cout << count << endl;
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 5524KB
stdin
3
3 1
3 2
10 6
stdout
7
4
173