# 「BZOJ4173」数学

0
26

## 题面

$\large{S(n,m)=\{k_{1},k_{2},\cdots k_{i}\}}$

$\large{n \%k+m\%k\geq k}$

$\large{\phi(n)\times \phi(m)\times\sum_{k\in S(n,m) }\phi(k)\%998244353}$

## Part 1

$\large{n=a_{1} \times k +b_{1} ,m=a_{2} \times k +b_{2}}$

$\large{b_{1}+b_{2} \geq k}$

$\large{(a_{1} \times k +b_{1})+(a_{2} \times k +b_{2}) \geq (a_{1}+a_{2}+1)\times k}$

$\large{n+m \geq (a_{1}+a_{2}+1)\times k}$

$\large{\lfloor \frac{n+m}{k} \rfloor \geq a_{1}+a_{2}+1}$

$\large{a_{1}=\lfloor \frac{n}{k} \rfloor ,a_{2}=\lfloor \frac{m}{k} \rfloor}$

$\large{\lfloor \frac{n+m}{k} \rfloor \geq \lfloor \frac{n}{k} \rfloor+\lfloor \frac{m}{k} \rfloor+1}$

$\large{\lfloor \frac{n+m}{k} \rfloor – \lfloor \frac{n}{k} \rfloor – \lfloor \frac{m}{k} \rfloor\geq 1}$

$\large{\lfloor\frac{x}{y}\rfloor=\frac{x}{y}-\{\frac{x}{y}\}}$

$\large{\frac{n+m}{k}-\{\frac{n+m}{k}\}-(\frac{n}{k}-\{\frac{n}{k}\}+\frac{m}{k}-\{\frac{m}{k}\})} \geq 1$

$\large{\{\frac{n}{k}\}+\{\frac{m}{k}\}-\{\frac{n+m}{k}\}}\geq 1$

$\large{0\leq\{\frac{n}{k}\}},\{\frac{m}{k}\},\{\frac{n+m}{k}\}<1$

$\large{1<\{\frac{n}{k}\}}+\{\frac{m}{k}\}-\{\frac{n+m}{k}\}<2$

$\large{\{\frac{n}{k}\}+\{\frac{m}{k}\}-\{\frac{n+m}{k}\}}\geq 1,\{\frac{n}{k}\}+\{\frac{m}{k}\}-\{\frac{n+m}{k}\}\in N^{+}$

$\large{\{\frac{n}{k}\}+\{\frac{m}{k}\}-\{\frac{n+m}{k}\}}= 1$

$\large{\lfloor \frac{n+m}{k} \rfloor – \lfloor \frac{n}{k} \rfloor – \lfloor \frac{m}{k} \rfloor= 1}$

## Part2

$\large{\sum_{k\in S(n,m)}\phi(k)}$

$\large{\sum_{n \%k+m\%k\geq k }\phi(k)}$

$\large{\sum_{k=1}^{n+m}\phi(k)\times\lfloor \frac{n+m}{k} \rfloor}-\sum_{k=1}^{n}\phi(k)\times\lfloor \frac{n}{k} \rfloor-\sum_{k=1}^{m}\phi(k)\times\lfloor \frac{m}{k} \rfloor$

$\large{n=\sum_{d|n}\phi(d)}$

$\large{\sum_{i=1}^{n+m}i-\sum_{i=1}^{n}i-\sum_{i=1}^{m}i=\frac{(n+m)\times(n+m-1)}{2}-\frac{n\times(n-1)}{2}-\frac{m\times(m-1)}{2}-}$

$\large{=n\times m}$

## 结论

$\large{ans=\large{\phi(n)\times \phi(m)\times n\times m\%998244353}}$

## 代码

#include <bits/stdc++.h>
using namespace std;

const int mod=998244353;

unsigned long long n,m;

unsigned long long phi(unsigned long long x)
{
unsigned long long ans=x;
for (unsigned long long i=2;i*i<=x;i++)
{
if (x%i==0)
{
ans-=ans/i;
while (x%i==0) x/=i;
}
}
if (x>1) ans-=ans/x;
return ans%mod;
}

int main()
{
cin>>n>>m;
cout<<(phi(n)%mod)*(phi(m)%mod)%mod*(n%mod)%mod*(m%mod)%mod;
return 0;
}


<