Guitar teacher questions do not move ah
First \ ([l_1, r_1], [l_2, r_2] \) is not very well done, we will consider split it into prefix information
设\(solve(n,m)=\sum_{i=0}^n\sum_{j=0}^m[m|(i\bigoplus j)]\)
So our answer becomes \ (solve (r_1, r_2) -solve (l_1-1, r_2) -solve (r_1, l_2-1) + solve (l_1-1, l_2-1) \)
Consider \ (solve (r_1, r_2) \) how demand
A very special case \ (^ n-2-R_1 =. 1, R_2. 1-m = 2 ^ \) , it may be assumed \ (n-<m \) , then \ ([0,2 ^ n) \ ) and \ ([0,2 ^ m) \) each of a selected number of exclusive oR up can take over \ ([0,2 ^ m) \) , and the number of times each occurrence are \ (2 ^ n \)
Obviously correctness
Consider extended to the more general case, we \ ([0, r_1) \ ) to split it, split into \ (\ log \) paragraph \ ([v, v + 2 ^ k) \) range, such as for he said \ (101010 \) , can be split into \ ([0,2 ^ 5), [2 ^ 5,2 ^ 5 ^ 3 + 2), [2 + 2 ^ 5 ^ 5 ^ 3,2 ^ + 2 3 ^ 2 + 1) \)
This split has a feature, if there \ (v \ neq 0 \) , then it must exist \ (v> 2 ^ k \) , the nature of this very important next
The \ ([0, r_1), [0, r_2) \) each split into \ (\ log \) after segment interval, we violent interval from each side of the election period is assumed to be \ ([x, x + 2 ^ A) \) and \ ([Y, Y + 2 ^ B) \) , or may assume \ (a <b \)
Thus ignoring \ (x, y \) in the case of two sections become \ ([A ^ 0,2), [0,2 ^ B) \) , then each of them can be selected from a different or take over \ ( [0,2 ^ b) \) and out of each value can be the exclusive oR \ (2 ^ a \) times
Now consider \ (x, y \) is introduced, not difficult to find because \ (X> A ^ 2 \) , so that the \ ([0,2 ^ a) \ ) to come up with a number, plus \ (X \ ) and exclusive oR \ (X \) is the equivalent; \ (Y \) there Similarly
Thus \ ([0,2 ^ b) \ ) every number and the out \ (x \ bigoplus y \) XOR what is true from the \ ([x, x + 2 ^ a) \) and \ ([y, y + 2 ^ b) \) each holding a number of exclusive oR out.
Therefore, now only requires a \ ([0,2 ^ b) \ ) has a number satisfying the exclusive-OR \ (x \ bigoplus y \) after mod \ m = 0) \ \ (\ rm number, such number multiplied by the number of \ (2 ^ a \) is the answer .
It will not be done here, and the next are Zute taught me.
We find that \ (x \ bigoplus y \) If it is not \ (0 \) , must be greater than the \ (2 ^ B \) , then \ (x \ bigoplus y \) and \ ([0,2 ^ b) \) number of XOR therein, certainly not necessary to change the \ (2 ^ b \) higher bit.
So that the desired number out of the exclusive OR is \ (m \) multiple, just let \ (x \ bigoplus y \) is less than \ (2 ^ b \) bits from full \ (0 \) accessible to the full \ (1 \) , to choose the \ (m \) multiples can.
Code
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int mod=998244353;
inline int dqm(int x) {return x<0?x+mod:x;}
inline int qm(int x) {return x>=mod?x-mod:x;}
LL l1,l2,r1,r2;int m,top[2];
struct Seg{LL v,k;}a[2][65];
inline LL getid(LL a,LL b) {return a%b==0?a/b:a/b+1;}
inline LL solve(LL n,LL k)
{
LL t=0,tot=0;
for(re LL i=63;i>=0;i--)
{
t|=(1ll<<i);
if(!(n&(1LL<<i))) continue;
LL l=k&t,r=l+(1ll<<i)-1;
LL L=getid(l,m),R=r/m;
tot=qm(tot+(R-L+1)%mod);
}
return tot;
}
inline int calc(LL n,LL m) {
++n,++m;int ans=0;
top[0]=top[1]=0;
LL now=0;
for(re LL i=63;i>=0;--i)
if(n>>i&1ll) {
a[0][++top[0]].v=now,a[0][top[0]].k=i;
now|=(1ll<<i);
}
now=0;
for(re LL i=63;i>=0;--i)
if(m>>i&1ll) {
a[1][++top[1]].v=now,a[1][top[1]].k=i;
now|=(1ll<<i);
}
for(re int i=1;i<=top[0];++i)
for(re int j=1;j<=top[1];++j) {
now=a[0][i].v^a[1][j].v;
LL mx=max(a[0][i].k,a[1][j].k),mn=min(a[0][i].k,a[1][j].k);
mn=(1ll<<mn);mn%=mod;
ans=qm(ans+1ll*solve(1ll<<mx,now)%mod*mn%mod);
}
return ans;
}
int main() {
scanf("%lld%lld%lld%lld%d",&l1,&r1,&l2,&r2,&m);
printf("%d\n",dqm(qm(calc(r1,r2)+calc(l1-1,l2-1))-qm(calc(l1-1,r2)+calc(r1,l2-1))));
return 0;
}