Huge Sequences
시간 제한1초메모리 제한2048 MB
각 질의 구간 안의 모든 부분 구간에 대해 a의 AND, b의 OR, c의 GCD를 곱한 값을 더해 2^32로 나눈 나머지를 구한다.
문제
Given three sequences , , and , define the value of the interval as the product of three factors:
- the bitwise AND of ,
- the bitwise OR of , and
- the greatest common divisor of .
There are queries. Each query provides an interval , and asks for the sum of the values of all intervals such that . As the answer may be large, find it modulo .
입력
The first line of input contains two integers and (; ).
The second line contains integers .
The third line contains integers .
The fourth line contains integers .
The constraints are: .
Each of the following lines contains two integers and and represents a query ().
출력
Output lines, each containing one integer: the corresponding answer modulo .