显然的区间筛法
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll L,R,k,n;
const int MAXN = 10000005;
int prime[MAXN],tot;
bool isx[MAXN];
void mkprime(){
for(int i=2;i<=n;i++){
if(!isx[i]){prime[++tot]=i;}
for(int j=1;i*prime[j]<=n&&j<=tot;j++){
int v=prime[j];
isx[i*v]=1;
if(i%v==0)break;
}
}
}
bool vis[MAXN];
int main(){
freopen("prime.in","r",stdin);
freopen("prime.out","w",stdout);
cin>>L>>R>>k;
n=sqrt(R);
n=min(n,k);
mkprime();
for(int i=1;i<=tot;i++){
int v=prime[i];
ll cur=1ll*v*(L/v);
if(cur<L)cur+=v;
if(cur==v)cur+=v;
for(;cur<=R;cur+=v)vis[cur-L]=1;
}
ll ans=0;
int up=R-L,i;
for(i=0;i<=up;i++){
if(!vis[i]) ans^=(i+L);
}
cout<<ans;
return 0;
}