# Chef Wars â€“ Return of the Jedi Codechef Solution

Chef Wars â€“ Return of the Jedi Codechef Solution: On the ice planet Hoth, Chef has run into his arch-nemesis, DarthForces. Darth has a peculiar fighting style â€• he does not attack, but simply defends and lets his opponent tire himself out.

Chef has a lightsaber which has anÂ attack powerÂ denoted byÂ PP. He keeps hitting Darth with the lightsaber. Every time he hits, Darthâ€™s health decreases by the current attack power of the lightsaber (byÂ PPÂ points), and afterwards,Â PPÂ decreases toÂ âŒŠP2âŒ‹âŒŠP2âŒ‹.

If the attack power becomesÂ 00Â before Darthâ€™s health becomesÂ 00Â or less, Chef dies. Otherwise, Darth dies. You are given Darthâ€™s initial healthÂ HHÂ and the initial attack powerÂ PP. Tell Chef if he can beat Darth or if he should escape.

### Input

• The first line of the input contains a single integerÂ TTÂ denoting the number of test cases. The description ofÂ TTÂ test cases follows.
• The first and only line of each test case contains two space-separated integersÂ HHÂ andÂ PP.

### Output

For each test case, print a single line containing the integerÂ 11Â if Chef can beat Darth orÂ 00Â otherwise.

### Constraints

• 1â‰¤Tâ‰¤1051â‰¤Tâ‰¤105
• 1â‰¤Pâ‰¤1051â‰¤Pâ‰¤105
• 1â‰¤Hâ‰¤1061â‰¤Hâ‰¤106

```2
10 4
10 8
```

```0
1
```

### Explanation

Example case 1:Â Chef attacks with powerÂ 44, Darthâ€™s health becomesÂ 66. Chef attacks with powerÂ 22, Darthâ€™s health becomesÂ 44. Chef attacks with powerÂ 11Â and Darthâ€™s health becomesÂ 33, but Chefâ€™s attack power becomesÂ 00.

Example case 2:Â Chef attacks with powerÂ 88, Darthâ€™s health becomesÂ 22. Chef attacks with powerÂ 44, Darthâ€™s health becomesÂ 00. Chef kills Darth.

## Chef Wars â€“ Return of the Jedi â€“ CodeChef Solution in JAVA

```import java.util.*;
import java.io.*;
class Codechef {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tt=0; tt<t; tt++) {
int h = sc.nextInt();
int p = sc.nextInt();
if ((h-p) >= p) {
System.out.println(0);
} else {
System.out.println(1);
}
}
}
}
```

## Chef Wars â€“ Return of the Jedi â€“ CodeChef Solution in CPP

```#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
while(a!=0 &&  b!=0){
a=a-b;
b=b/2;
if(a<=0){
cout<<1<<endl;
break;
}
else if(b==0) {cout<<0<<endl;break;}
}
}
}```

## Chef Wars â€“ Return of the Jedi-CodeChef Solution in Python

```for t in range(int(input())):
h,p=map(int,input().split())
while True:
h=h-p
if h<=0:
print(1)
break
else:
p=p//2
if p==1 and (h-p)>0:
print(0)
break
```

Disclaimer:Â The above Problem (Chef Wars â€“ Return of the JediÂ ) is generated byÂ CodeChef but the solution is provided byÂ Â Chase2learn.This tutorial is only forÂ EducationalÂ andÂ LearningÂ purpose.

Sharing Is Caring