标签:
枚举i,j相当于枚举两点且确定里面还有整点。好巧啊。。。。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1050 using namespace std; long long n,m,c[maxn*maxn][4]; long long gcd(long long a,long long b) { if (b==0) return a; return gcd(b,a%b); } void get_table() { c[0][0]=1; for (long long i=1;i<=(n+1)*(m+1);i++) { c[i][0]=1; for (long long j=1;j<=3;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; } } long long get_ans() { long long ret=0; for (long long i=1;i<=n;i++) for (long long j=1;j<=m;j++) { long long d=gcd(i,j); if (d!=1) ret+=(d-1)*(n-i+1)*(m-j+1); } return 2*ret; } int main() { scanf("%lld%lld",&n,&m); get_table(); printf("%lld\n",c[(n+1)*(m+1)][3]-(m+1)*c[n+1][3]-(n+1)*c[m+1][3]-get_ans()); return 0; }
标签:
原文地址:http://www.cnblogs.com/ziliuziliu/p/5972686.html