Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- int main()
- {
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- ll height,leaf,i,j,k,a,b,c,d,e,barbe,two_er_power,t,cas,total_node;
- scanf("%lld",&t);
- for(cas=1; cas<=t; cas++)
- {
- scanf("%lld %lld",&height,&leaf);
- two_er_power=1,total_node=0;
- total_node=height+1;
- leaf-=1;
- while(true)
- {
- if(two_er_power>=leaf)
- {
- total_node+=(leaf*height);
- break;
- }
- else
- {
- total_node+=(two_er_power*height);
- leaf-=two_er_power;
- two_er_power*=2;
- height--;
- }
- }
- printf("Case %lld: %lld\n",cas,total_node);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment