您的位置:首页 > 其它

[组合计数] BZOJ 3505 [Cqoi2014]数三角形

2016-07-13 16:22 190 查看
减去共线的就好了

线上的整点用gcd

#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;

ll Gcd(ll a,ll b){
if (a<b) return Gcd(b,a);
return b?Gcd(b,a%b):a;
}

ll n,m;
ll ans;

int main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
scanf("%lld%lld",&n,&m);
ans=((n+1)*(m+1))*((n+1)*(m+1)-1)*((n+1)*(m+1)-2)/6;
for (int i=0;i<=n;i++)
for (int j=0;j<=m;j++)
{
if (!i && !j) continue;
ll t=(n-i+1)*(m-j+1)*(Gcd(i,j)-1);
ans-=t;
if (i && j) ans-=t;
}
printf("%lld\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: