Electric Fence

描述

 In this problem, `lattice points' in the plane are points with integer coordinates.

In order to contain his cows, Farmer John constructs a triangular electric fence by stringing a "hot" wire from the origin (0,0) to a lattice point [n,m] (0<=;n<32,000, 0<m<32,000), then to a lattice point on the positive x axis [p,0] (0<p<32,000), and then back to the origin (0,0).

A cow can be placed at each lattice point within the fence without touching the fence (very thin cows). Cows can not be placed on lattice points that the fence touches. How many cows can a given fence hold?

输入

 The single input line contains three space-separated integers that denote n, m, and p.

 输出

A single line with a single integer that represents the number of cows the specified fence can hold.

 样例输入

 7 5 10

样例输出

20

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,p;
    scanf("%d%d%d",&n,&m,&p);
    printf("%d\n", ((p*m - __gcd(n, m) - p - __gcd(abs(n-p), m) + 2) )/2);//p*m三角形面积
    /*/皮克定理 S = n + s/2 -1;
    多边形面积=多边形内部的格点数+多边形边上格点二分之一-1;
    直角边 x,y 上斜角上的点为gcd(x,y)-1;
    /*/
}
View Code

猜你喜欢

转载自www.cnblogs.com/llhsbg/p/11563344.html