ans=所有的三点排列-共行的-共列的-斜着一条线的

斜着的枚举每个点和原点的gcd,反过来也可以,还能左右,上下挪

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
long long ans,line,row,tot,n,m;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int main(){
	scanf("%lld%lld",&n,&m);n++,m++;
	tot=n*m;
	ans=tot*(tot-1)*(tot-2);
	ans/=6;
	line=n*(n-1)*(n-2)/6;
	row=m*(m-1)*(m-2)/6;
	ans-=m*line; ans-=n*row;
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++)
		{
			int k=gcd(i,j);
			if(k>1)ans-=2*(k-1)*(n-i)*(m-j);
		}
	}
	printf("%lld\n",ans);
}


相关文章:

  • 2021-10-06
  • 2021-09-28
  • 2021-08-05
  • 2022-01-23
  • 2021-12-20
  • 2022-02-07
  • 2022-12-23
  • 2021-07-21
猜你喜欢
  • 2021-05-31
  • 2021-05-15
  • 2021-12-13
  • 2022-12-23
  • 2021-11-02
  • 2021-10-01
  • 2021-07-03
相关资源
相似解决方案