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