bzoj 3505 [Cqoi2014]数三角形——排列组合

时间:2022-01-04 09:49:07

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505

好题!一定要经常回顾!

那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的gcd-1 真是很妙。

https://blog.csdn.net/u012288458/article/details/48624859

https://www.cnblogs.com/Var123/p/5377616.html

然而还可以递推?https://www.cnblogs.com/liu-runda/p/5993244.html 反正没管……

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int n,m;
ll ans;
ll C(int x)
{
return (ll)x*(x-)*(x-)/;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
scanf("%d%d",&n,&m);n++;m++;
ans=C(n*m)-n*C(m)-m*C(n);
for(int i=;i<n;i++)// bh node from 0 to n-1
for(int j=;j<m;j++)
{
ll num=gcd(i,j)-;
if(num>=)ans-=num*(n-i)*(m-j)*;
}
printf("%lld",ans);
return ;
}