#nt505. 区间筛

区间筛

Segmented Sieve

Problem Description

Given two numbers l,rl, r, find all primes pp in the range l∼rl \sim r.

To keep the output from being too large and to prevent precomputing answers from a table, you are also given a,ba, b; output the XOR sum of (a⋅p+b) mod 232(a \cdot p + b) \bmod 2^{32} over all such primes.

Input Format

The first line contains four integers l,r,a,bl, r, a, b.

Output Format

Output one integer: the answer.

Sample Input

1 100 1 0

Sample Output

64

Constraints

For all data, 1≤l≤r≤10141 \leq l \leq r \leq 10^{14}, 0≤a,b<2320 \leq a, b < 2^{32}, r−l≤107r - l \leq 10^7.