题解里都在线性求,但其实不需要,也能1.61sAC,附上代码,求加入题解:
#include <cstdio>
#include <cctype>
struct istream{
template <typename T>
istream &operator>>(T &x){
x = 0;
char c = getchar_unlocked();
while (!isdigit(c)) c = getchar_unlocked();
while (isdigit(c)) x = x * 10 + c - '0',c = getchar_unlocked();;
return *this;
}
}cin;
const int maxn = 5e6 + 5,mod = 998244353;
auto exgcd(int a,int b){//auto->result
struct result{int x,y,gcd;};
if (b == 0) return (result){1,0,a};
result res = exgcd(b,a % b);
return (result){res.y,res.x - a / b * res.y,res.gcd};
}
int inv(int a,int p){return (exgcd(a,p).x + p) % p;}
int main(){
int T,N,ans = 0,fac[maxn],ifac[maxn];
cin >> T >> N;
fac[0] = ifac[0] = 1;
for (int i = 1;i <= N;i++){
fac[i] = (long)fac[i - 1] * i % mod;
ifac[i] = inv(fac[i],mod);
}
while (T--){
int n,m;
cin >> n >> m;
ans ^= (long)fac[n] * ifac[m] % mod * ifac[n - m] % mod;/*c(n,m) = n! / (m! * (n - m)!)*/
}
printf("%d\n",ans);
return 0;
}