Skip to main content

Cars and Bikes Problem Code: TYRES | CodeChef

Problem:

Chef opened a company which manufactures cars and bikes. Each car requires 

4 tyres while each bike requires 2 tyres. Chef has a total of N tyres (N is even). He wants to manufacture maximum number of cars from these tyres and then manufacture bikes from the remaining tyres.

Chef's friend went to Chef to purchase a bike. If Chef's company has manufactured even a single bike then Chef's friend will be able to purchase it.

Determine whether he will be able to purchase the bike or not.

Input Format

  • The first line contains an integer T denoting the number of test cases. The T test cases then follow.
  • The first line of each test case contains an integer N denoting the number of tyres.

Output Format

For each test case, output YES or NO depending on whether Chef's friend will be able to purchase the bike or not. Output is case insensitive.

Constraints

  • 1T100
  • 2N1000
  • N is even

Sample Input 1 

3
8
2
6

Sample Output 1 

NO
YES
YES

Explanation

  • For the first test case Chef, will manufacture 2 cars and will thus use all the 8 tyres and thus could not manufacture any bike.

  • For the second test case, Chef cannot manufacture any car since there are not enough tyres and will thus manufacture only a single bike which will be purchased by Chef's friend.

  • For the third test case, Chef will manufacture 1 car and thus use 4 tyres. From the remaining 2 tyres, Chef can manufacture a single bike which will be purchased by Chef's friend.

Solution:

#include <iostream>
using namespace std;

int main() {
// your code goes here
int t; cin>>t;
while(t--){
    int n;cin>>n;
    while(n>4){
        n%=4;
    }
    if(n>=2 && n%2==0)
        cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}
return 0;
}

Comments

Must Read:

Course DH ASE B3 Slot3 Mock 1 Handson | RDBMS

DH ASE B3          Slot3              Mock 1                  Handson: RDBMS

Software Engineering Concepts Software Engineering Fundamentals Post-Quiz

  Software Engineering Concepts       Software Engineering Fundamentals            Post-Quiz

Accenture Mock Quiz | Part 4

  Question  31 Correct Marked out of 1.00 Flag question Question text What will be the output of the following Java code? class Test extends Throwable { } class Base extends Test {} public class Main { public static void main(String args[]) { try { throw new Base(); } catch(Test t) { System.out.println("Test Exception"); } finally { System.out.println("Finally block "); } } } Select one: a.  Complilation error : Bass calss can't extends Test b.  print-"Test Exception" c.  Complilation error: Test Class cant extends Throwable d.  print - "Test Exception" "Finally block "   Feedback The correct answer is: print - "Test Exception" "Finally block " Question  32 Correct Marked out of 1.00 Flag question Question text Which of the following statement(s) is/are TRUE? (i) In a non-correlated(independent) subquery, the subquery is always executed only onc...

Subscribe to Get's Answer by Email