Type Here to Get Search Results !

Brick Game | HackerEarth Programming Problems and Solutions by CodingHumans |

0
Brick Game
Difficulty : easy

Task

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 ix2 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

Explanation
Sample Explanation:

13 bricks are there :

Patlu Motu

1 2 

2 4

3 1 ( Only 1 remains)

Hence, Motu puts the last one.





Recommended: Please try your approach on your integrated development environment (IDE) first, before moving on to the solution.

Few words from CodingHumans : Don't Just copy paste the solution, try to analyze the problem and solve it without looking by taking the the solution as a hint or a reference . Your understanding of the solution matters.

HAVE A GOOD DAY 😁





Solution 
( Java )


import java.util.Scanner;
class TestClass {
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int p; // patlus pick
        int m; // motus pick
        int b=sc.nextInt(); // total no of bricks 
        int i=1; // ith time pick
        int a=0;  //variable to add total bricks picked
        while(a<=b){
            p=i;
            if(a+p>=b){
                System.out.println("Patlu");
                break;
            }
            m=2*i;
            if(a+p+m>=b){
                System.out.println("Motu");
                break;
            }
            a=a+p+m; //counting total brickes used
            i++;   // increasing respective bricks in next pick
        }
        
        }
       
    }

If you have any doubts regarding this problem or  need the solution in other programming languages then leave a comment down below . 

Post a Comment

0 Comments

Top Post Ad

Below Post Ad