Bricks Game | Competitive Programming Questions with Answers in Java
Competitive Programming Questions with Answers in Java
Bricks Game
Problem
Patlu and Motu works in a building construction, they have to put some number of bricks N from one place to another, and started doing their work. They decided , they end up with a fun challenge who will put the last brick.
They to follow a simple rule, In the i'th round, Patlu puts i bricks whereas Motu puts i x 2 bricks.
There are only N bricks, you need to help find the challenge result to find who put the last brick.
Input
First line contains an integer N.
Output
Output "Patlu" (without the quotes) if Patlu puts the last bricks ,"Motu"(without the quotes) otherwise.
Constraints
1 ≤ N ≤ 10000
Sample Input
13
Sample Output
Motu
Solution
import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
int n, i, m=0, p=0, c;
Scanner s = new Scanner(System.in);
n = s.nextInt();
c = n;
for(i=1; i<=n; i++)
{
p = p + i;
m = m + i * 2;
c = c - i - i * 2;
if(p+m < n && c < i )
{
System.out.println("Patlu");
System.exit(0);
}
}
System.out.println("Motu");
}
}
Comments
Post a Comment