Farjana_akter

Untitled

Jul 26th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. int main()
  7. {
  8. // freopen("input.txt","r",stdin);
  9. // freopen("output.txt","w",stdout);
  10. ll height,leaf,i,j,k,a,b,c,d,e,barbe,two_er_power,t,cas,total_node;
  11. scanf("%lld",&t);
  12. for(cas=1; cas<=t; cas++)
  13. {
  14. scanf("%lld %lld",&height,&leaf);
  15. two_er_power=1,total_node=0;
  16. total_node=height+1;
  17. leaf-=1;
  18. while(true)
  19. {
  20. if(two_er_power>=leaf)
  21. {
  22. total_node+=(leaf*height);
  23. break;
  24. }
  25. else
  26. {
  27. total_node+=(two_er_power*height);
  28. leaf-=two_er_power;
  29. two_er_power*=2;
  30. height--;
  31. }
  32. }
  33. printf("Case %lld: %lld\n",cas,total_node);
  34. }
  35. return 0;
  36. }
  37.  
Add Comment
Please, Sign In to add comment