-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXPENSES.cpp
More file actions
59 lines (34 loc) · 934 Bytes
/
EXPENSES.cpp
File metadata and controls
59 lines (34 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*Chef has made a list for his monthly expenses. The list has N expenses with index 1 to N.
The money spent on each expense depends upon the monthly income of Chef.
Chef spends 50% of his total income on the expense with index 1.
The money spent on the i th
expense (i>1) is equal to 50\%50% of the amount remaining, after paying for all expenses with indices less than i.
Given that Chef earns 2^X
rupees in a month, find the amount he saves after paying for all N expenses.*/
#include <iostream>
#include<math.h>
using namespace std;
void ans();
int main() {
// your code goes here
int test;
cin>>test;
while(test--){
ans();
}
return 0;
}
void ans(){
int n,x;
cin>>n>>x;
int income = pow(2,x);
if(n==1)
cout<<income/2<<endl;
else{
int still = income/2;
for(int i = 2;i<=n;i++){
still = still/2;
}
cout<<still<<endl;
}
}