bzoj3505 [Cqoi2014]数三角形
先算在n*m个点中任选3个的方案数,再减去三点共线的方案数
我为什么要做这种水题?因为我很弱
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 void inin(int &ret) 27 { 28 ret=0;int f=0;char ch=getchar(); 29 while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} 30 while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar(); 31 ret=f?-ret:ret; 32 } 33 int n,m; 34 int C(int a,int b=3) 35 { 36 return a*(a-1)*(a-2)/6; 37 } 38 int gcd(int a,int b){int c;while(a%b)c=a%b,a=b,b=c;return b;} 39 int main() 40 { 41 inin(n),inin(m); 42 n++,m++; 43 LL now=n*m; 44 LL ans=1LL*now*(now-1)*(now-2)/6; 45 ans-=1LL*m*C(n,3)+1LL*n*C(m,3); 46 re(i,1,n-1) 47 re(j,1,m-1) 48 { 49 int temp=gcd(i,j); 50 if(temp>=2) 51 ans-=1LL*(temp-1)*2*(n-i)*(m-j); 52 } 53 cout<<ans; 54 return 0; 55 }