4173: 数学
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 460 Solved: 226
[Submit][Status][Discuss]
Description
Input
输入文件的第一行输入两个正整数 。
Output
如题
Sample Input
Sample Output
HINT
N,M<=10^15
Source
分析:
$m mod k+n mod k>=k$可以转化为以下的式子...
$n-left lfloor frac{n}{k} ight floor*k+m-left lfloor frac{m}{k} ight floor*k>=k$
$n+m-k*( left lfloor frac{n}{k} ight floor+left lfloor frac{m}{k} ight floor )>=k$
$left lfloor frac{n+m}{k} ight floor-left lfloor frac{n}{k} ight floor-left lfloor frac{m}{k} ight floor>=1$
也就是$left lfloor frac{n+m}{k} ight floor-left lfloor frac{n}{k} ight floor-left lfloor frac{m}{k} ight floor=1$
$sum_ {left lfloor frac{n+m}{k} ight floor-left lfloor frac{n}{k} ight floor-left lfloor frac{m}{k} ight floor=1} phi(k)$
$=sum_ {k=1}^{n+m} phi(k)*leftlfloor frac{n+m}{k} ight floor-sum_ {k=1}^{n} phi(k)*leftlfloor frac{n}{k} ight floor-sum_ {k=1}^{m} phi(k)*leftlfloor frac{m}{k} ight floor$
然后我们看$sum_ {k=1}^{n} phi(k)*leftlfloor frac{n}{k} ight floor$是什么...
因为一个数的因子的欧拉函数之和为它本身...所以可以有以下的式子...
$sum_ {k=1}^{n} phi(k)*leftlfloor frac{n}{k} ight floor=sum_ {i=1}^{n} sum_ {kmid i} phi(k)=sum_ {i=1}^{n} i$
那么答案就是$phi(n)*phi(m)*n*m$...
代码:
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> //by NeighThorn #define int long long using namespace std; int n,m,mod=998244353; inline int phi(int x){ int ans=x,y=sqrt(x); for(int i=2;i<=y;i++) if(x%i==0){ ans=ans/i*(i-1); while(x%i==0) x/=i; } if(x!=1) ans=ans/x*(x-1); return ans%mod; } signed main(void){ scanf("%lld%lld",&n,&m); int ans=phi(n)*phi(m)%mod*(n%mod)%mod*(m%mod)%mod; printf("%lld ",ans); return 0; }
By NeighThorn