# Guess 2 or 5

Guess 2 or 5 is the first problem of the HackerRank Contest GOC-18. It is an easy problem. The minimum requirement to solve this problem is the knowledge of if-else. Time complexity is \( \mathcal O(1) \) for each test case.

Here we are given a number in each test case which would be either be divisible by \(5\) or \(2\) or \(10\) or by none of them. For each of divisibility condition, we have to print **“TWO”**,** “FIVE”**, **“BOTH”** or **“NONE”** respectively.

Here the order of placing if-else statement is very important. Let’s take an example of \(20\), here desired answer should be **“BOTH”**, but if you place divisibility check condition of either \(5 \) or \(2\) then answer would be **“FIVE”** or **“TWO”** which is wrong.

Below is the simple C++ code.

#include <iostream> using namespace std; int main() { int test; cin>>test; while(test--) { long n; cin>>n; if(n%10==0) cout<<"BOTH\n"; else if(n%2==0) cout<<"TWO\n"; else if(n%5==0) cout<<"FIVE\n"; else cout<<"NONE\n"; } return 0; }

This editorial is contributed by Ravi Kant. If you like eLgo Academy and would like to contribute, you can mail your article to admin@elgoacademy.org. See your article appearing on the eLgo Academy page and help others. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.