2017年10月30日提高组T2 数论
Description
聪明的0v0正在学习莫比乌斯反演。
她看到了这样的一道题:有n*m个人站成了一个n*m的方阵……
剩下的题面,聪明的0v0不记得了。但是,她通过自己高超的数论技巧,给出了一个转化后的模型:给出n和m,求
聪明的0v0当然知道怎么做了,但是她想考考你。
Input
一行三个正整数n,m,p。
Output
一行一个非负整数,设答案为x,输出x mod p。
Sample Input
1 2 998244353
Sample Output
2
Hint
【数据规模和约定】
30% n,m<=2000 p=998244353。
30% n*m<=10^9 n,m<=10^5 p为质数
20% n,m<=10^6 p为质数
20% n,m<=10^7 p为合数
对于所有数据,保证p<=10^9
分析:打表发现,答案就是 n*m mod p。 其实,原式的物理意义,就是从坐标原点(0,0),用每一种合 法的斜率,穿过坐标[1~n,1~m]的方阵中的整点的个数,总数即 n*m。
代码
#include <cstdio>
using namespace std;
long long n,m,k;
int main()
{
// freopen("math.in","r",stdin);
// freopen("math.out","w",stdout);
scanf("%d%d%d",&n,&m,&k);
printf("%d",n*m%k);
fclose(stdin);
fclose(stdout);
}