Različitost
시간 제한2초메모리 제한1024 MB
주기가 각각 n과 m인 두 주기 수열의 첫 k개 항에 대해 a_i XOR b_i의 합을 구한다. k는 10^18까지 커질 수 있다.
문제
Two infinite periodic sequences of integers, and , are given, defined by their periods of lengths and , respectively. This means that the natural numbers and are given, as well as the numbers and , for which and hold for every natural number .
Additionally, given a natural number , we define the "diversity" of these two sequences as the sum for each . (Here, denotes the bitwise exclusive OR operation, which produces ones in the positions where the binary digits of the two numbers differ. For example, .)
Your task is to calculate the diversity of the given sequences.
입력
In the first line, there are , , and (, ), which are the numbers from the task description.
In the second line, there are integers (, ).
In the third line, there are integers (, ).
출력
Because the answer can be very large, output the remainder of the answer when divided by in a single line.