codeforces 1058D.Vasya and Triangle(数论?)

                                                                             Vasya and Triangle

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has got three integers nn, mm and kk. He'd like to find three integer points (x1,y1)(x1,y1), (x2,y2)(x2,y2), (x3,y3)(x3,y3), such that 0≤x1,x2,x3≤n0≤x1,x2,x3≤n, 0≤y1,y2,y3≤m0≤y1,y2,y3≤m and the area of the triangle formed by these points is equal to nmknmk.

Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.

Input

The single line contains three integers nn, mm, kk (1≤n,m≤1091≤n,m≤109, 2≤k≤1092≤k≤109).

Output

If there are no such points, print "NO".

Otherwise print "YES" in the first line. The next three lines should contain integers xi,yixi,yi — coordinates of the points, one point per line. If there are multiple solutions, print any of them.

You can print each letter in any case (upper or lower).

Examples

input

Copy

4 3 3

output

Copy

YES
1 0
2 3
4 1

input

Copy

4 4 7

output

Copy

NO

Note

In the first example area of the triangle should be equal to nmk=4nmk=4. The triangle mentioned in the output is pictured below:

codeforces 1058D.Vasya and Triangle(数论?)_第1张图片

In the second example there is no triangle with area nmk=167nmk=167.

 

一、原题地址

点我传送

 

二、大致题意

给出n、m、k.求一个三角形使它的面积等于n*m/k  并且这个三角形的三个顶点所在的坐标为整数点,且顶点满足0<=x<=n,0<=y<=m.询问是否存在这样的三角形。若存在则输出任意一种符合情况的三个顶点。

 

三、思路

  想解决这个问题,需要了解皮克定理。

  把面积n*m/k 乘以二,变成S=2*n*m/k 。那么这个S必然是一个整数。若把这个三角形的一个顶点设在(0,0),那么存在这么一个直角三角形(a,0)、(0,b).使得a*b=2*n*m/k.

问题就变成了寻找范围在[0,n]之间的a和在[0,m]之间的b。

 

四、代码

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }
LL GCD(LL a, LL b) { return a == 0 ? b : GCD(b % a, a); }

LL n, m, k;
int main()
{
	scanf("%lld %lld %lld", &n, &m, &k);
	if (2 * n*m%k != 0)
	{
		printf("NO\n");
	}
	else
	{
		if (k & 1)
		{
			LL tk;
			LL t = GCD(2 * n, k);
			LL a = 2 * n / t;
			tk = k / t;
			LL b = m / tk;
			if (a <= n&&b <= m)
			{
				printf("YES\n");
				printf("0 0\n");
				printf("%lld 0\n", a);
				printf("0 %lld\n", b);
			}
			else if (a <= m&&b <= n)
			{
				printf("YES\n");
				printf("0 0\n");
				printf("0 %lld\n", a);
				printf("%lld 0\n", b);
			}
			else
			{
				LL t = GCD(2 * m, k);
				LL a = 2 * m / t;
				tk = k / t;
				LL b = n / tk;
				if (a <= m&&b <= n)
				{
					printf("YES\n");
					printf("0 0\n");
					printf("0 %lld\n", a);
					printf("%lld 0\n", b);
				}
				else
				{
					printf("YES\n");
					printf("0 0\n");
					printf("0 %lld\n", b);
					printf("%lld 0\n", a);
				}
			}
		}
		else
		{
			LL tk;
			tk = k / 2;
			LL t = GCD(n, tk);
			LL a = n / t;
			tk /= t;
			LL b = m / tk;
			printf("YES\n");
			printf("0 0\n");
			printf("%lld 0\n", a);
			printf("0 %lld\n", b);
		}
	}
	getchar();
	getchar();

}

 

你可能感兴趣的:(codeforces 1058D.Vasya and Triangle(数论?))