/* Idea: 1. Select three points 2. Remove the peer situation 3. Remove the same column case 4. The enumeration rectangle size removes the repetition */#pragma comment (linker, "/stack:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath># include<queue> #include <stack> #include <vector> #include <set> #include <map> #define L ( x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define BUG printf ("hihi\n") #define EPS 1e-8 typedef __int64 LL;TYPEDEF Long Long ll;using namespace std; #define INF 0x3f3f3f3f#define N 1005int n,m;ll C (ll n,ll m) { if (m>n) return 0; ll Ans=1; for (int i=0;i<m;i++) ans=ans* (n-i)/(i+1); return ans;} int main () {int i,j,ca=0; while (scanf ("%d%d", &n,&m), n+m) {ll ans=c ((n+1) * (m+1), 3); ans-= (LL) c (n+1,3) * (m+1) + (LL) c (m+1,3) * (n+1); cout<<ans<<endl; for (i=1;i<=n;i++) for (j=1;j<=m;j++) {int c=__gcd (I,J); ans-= (ll) (c-1) * (n-i+1) * (m-j+1) * * *; ans-= (LL) (c (c,2) * (n-i+1) * (m-j+1) *2;//before WA where such//printf ("%d%d%d%lld\n", I,j,c, (LL) C (c,2) * (n-i+1) * (m-j+1) * 2); } printf ("Case%d:%lld\n", ++ca,ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Uva 12075 counting triangles (Rong Chi)