见代码注释

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll t, l, r, dp[30][20][2][2], ans;
int bit[30];//存储每一位的值

ll DFS(int pos, int legal0, bool before0, bool isMax, bool has007) {
    //pos:当前位数,legal0:合法的0的个数,出现在任意非0数后的0才算合法, before0:记录是否出现了非0数,isMax:当前是否达到了可能的最大值,has007:当前是否有了合法的007组合
    if(pos == 0) return has007;//能够到最后一步并且有了合法的007,说明合理
    if(!isMax && dp[pos][legal0][before0][has007]) return dp[pos][legal0][before0][has007];
    //已经计算过的数据就可以拿来重复利用
    ll cnt = 0;
    ll maxNum = isMax ? bit[pos] : 9;
    for(int i = 0; i <= maxNum; i++){
        cnt += DFS(pos - 1, legal0 + (before0 && i == 0), i || before0, isMax && i == maxNum, has007 || (legal0 >= 2 && i == 7));
    }
    return isMax ? cnt : dp[pos][legal0][before0][has007] = cnt;
    //未达到当前位数的最大值则将数据记忆下来
}

ll tran(ll num) {
    int pos = 0;
    while(num){
        bit[++pos] = num % 10;
        num /= 10;
    }
    return DFS(pos, 0, false, true, false);
}

int main() {
    cin>>t;
    ll ans = 0;
    while(t--){
      cin>>l>>r;
      ans ^= tran(r) - tran(l - 1);
    }
    cout<<ans<<endl;
    return 0;
}