BZOJ2659算不出的算式不正经题解

题目链接

https://www.lydsy.com/JudgeOnline/problem.php?id=2659

分析

难得做到此类打表题目,不觉回想到NOIp2017考场上的SB经历

这道题看到这么吓人的算式,当然是要....

咳咳,像我这种菜鸡当然是先要打个表

好象没什么规律,但我们可以找找特殊项

比如(3,3)和(5,5),(7,7),大胆猜想若两数相同对于奇质数\(x\)\(ans=(x*x-1)/4\)

然后就往4方面去想,把所有答案乘以4得到另一张表,然后就很容易发现规律了

\[ans= \begin{cases} p*q/4& \text{p=q}\\ (p-1)*(q-1)/4& \text{p!=q} \end{cases}\]

证明

数竞队的还没有回应,

不过在网上找到一篇不错的

https://www.cnblogs.com/Mychael/p/9115847.html

个人觉得讲得比其他blog好一点

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cctype>
#include <vector>
#define ll long long 
#define ri register int 
const int maxn=100005;
const int inf=0x7fffffff; 
int main(){
 int a,b;
 scanf("%d %d",&a,&b);
 if(a==b)printf("%lld\n",1ll*a*b/4);
 else printf("%lld\n",1ll*(a-1)*(b-1)/4);
 return 0;
}

猜你喜欢

转载自www.cnblogs.com/Rye-Catcher/p/9313709.html