题目链接
题解
真没想到,,
观察式子
[sumlimits_{k = 1}^{frac{p - 1}{2}} lfloor frac{kq}{p}
floor
]
有没有想到斜率?
如果构造函数
[y = frac{q}{p}x
]
那么该式子的含义就是直线在(x in [1,frac{p - 1}{2}])下方的整点数
容易发现另一条直线是其反函数,所以它们的点可以补成一个矩形
而且题目保证(p,q)为质数,除非(p,q)相等,否则直线上是不会有整点的
所以
[ans = frac{(p - 1)(q - 1)}{4}
]
当(p = q)时,(ans)要加上(frac{p - 1}{2})
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline LL read(){
LL out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
LL p,q;
int main(){
p = read(); q = read();
LL ans = p / 2 * (q / 2);
if (p == q) ans += p / 2;
printf("%lld
",ans);
return 0;
}