Uva 12075 counting triangles (Rong Chi)

Source: Internet
Author: User


/* 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.