Rhezo and divisibility by 7

4.4

5 votes
Mathematics, range query, Easy-Medium, Segment tree, Data Structures
Problem

Rhezo is obsessed with the number 7 and likes numbers that are divisible by 7.

He has a big number of N digits and Q questions. In each of the question, he wants to find if the number formed by the string between indices Li and Ri is divisible by 7 or not. As he is very weak at programming, you should help him in this task.

Input:

First line contains the number consisting of N digits. Next line contains Q, denoting the number of questions. Each of the next Q lines contains 2 integers Li and Ri.

Output:

For each question, print "YES" or "NO", if the number formed by the string between indices Li and Ri is divisible by 7.

Constraints:

1N105

1Q105

1Li,RiN

Sample Input
357753
3
1 2
2 3
4 4
Sample Output
YES
NO
YES
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first query, number will be 35 which is clearly divisible by 7.

Editor Image

?