Treasure Hunt | Codechef
While his trip to an ancient palace Harry found a box while wandering in the palace.
The box is rectangular and consists of a lock on it's each vertical face. He has also found two keys attached to the top of the box. The box displays an arbitrary number N on its top.
You have to find out whether this box can be opened by this number or not.
The box can be opened by a number, iff it is a multiple of a number of keys and number of locks and number of corners in the rectangular box(all 3 conditions satisfying simultaneously).
If the box can be opened by the displayed number print YES otherwise NO.
The box is rectangular and consists of a lock on it's each vertical face. He has also found two keys attached to the top of the box. The box displays an arbitrary number N on its top.
You have to find out whether this box can be opened by this number or not.
The box can be opened by a number, iff it is a multiple of a number of keys and number of locks and number of corners in the rectangular box(all 3 conditions satisfying simultaneously).
If the box can be opened by the displayed number print YES otherwise NO.
Input
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases is as follows.
- The first line of each test case contains a single integer N, which is displayed on the top of the box.
Output
For each test case, Output YES if the box can be opened otherwise NO.
Constraints
- 1 ≤ T ≤ 108
- 1 ≤ N ≤ 1030
Subtasks
Subtask #1 (10 points):
- 1 ≤ N ≤ 108
Subtask #2 (40 points):
- 1 ≤ N ≤ 1018
Subtask #3 (50 points): original constraints
Input: 3 72 32 20 Output: YES YES NO
Solution(C++):
#include
using namespace std;
void check_fact(string num)
{
int n=0 ;
if(num.size()==1)
n=num[0]-'0';
if(num.size()==2)
n=(num[num.size()-2]-'0')*10 + num[num.size()-1];
else
{
n=(num[num.size()-3]-'0')*100 + (num[num.size()-2]-'0')*10 + num[num.size()-1];
}
if(n%8==0)
cout<<"YES"<
else
cout<<"NO"<
}
int main()
{
int t;
cin>>t;
while(t--)
{
string num;
cin>>num;
check_fact(num);
}
return 0;
}
Comments
Post a Comment