Description
聪明的0v0正在学习莫比乌斯反演。
她看到了这样的一道题:有n*m个人站成了一个n*m的方阵……
剩下的题面,聪明的0v0不记得了。但是,她通过自己高超的数论技巧,给出了一个转化后的模型:给出n和m,求
聪明的0v0当然知道怎么做了,但是她想考考你。
Input
一行三个正整数n,m,p。
Output
一行一个非负整数,设答案为x,输出x mod p。
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
Solution
不难想到当只有gcd(i,j)=1的条件时就是能在原点直接看到的点的数量,这里乘上min(⌊ni⌋,⌊ni⌋) 就是枚举的这条斜率覆盖了多少个点。由于每个点最多被覆盖了一次,答案就是n*m%p了
注意要开ll
Code
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#define rep(i, st, ed) for (int i = st; i <= ed; i += 1)
#define drp(i, st, ed) for (int i = st; i >= ed; i -= 1)
#define erg(i, st) for (int i = ls[st]; i; i = e[i].next)
#define fill(x, t) memset(x, t, sizeof(x))
#define min(x, y) ((x)<(y)?(x):(y))
#define max(x, y) ((x)>(y)?(x):(y))
#define ld long double
#define db double
#define ll long long
#define INF 0x3f3f3f3f
#define N 1001
#define E 1001
#define L 1001
inline ll read() {
ll x = 0, v = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; v *= (ch == '-')?(-1):(1), ch = getchar());
for (; ch <= '9' && ch >= '0'; (x *= 10) += ch - '0', ch = getchar());
return x * v;
}
int main(void) {
ll n = read();
ll m = read();
ll p = read();
std:: cout << (n % p * m % p) % p << std:: endl;
return 0;
}