Cod sursa(job #1630730)

Utilizator IAmSdlSchmidt Daniel IAmSdl Data 5 martie 2016 10:58:40
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.24 kb
// Algoritmul lui Euclid extins.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

long long cmmdc(long long a, long long b)
{
	long long t;
	while (b)
	{
		t = a%b;
		a = b;
		b = t;	
	}
	return a;
}

int main()
{
	size_t n;
	long long a, b, c, d;
	double x, y1,y2;
	fin >> n;
	for (size_t i = 1; i <= n; i++)
	{
		fin >> a >> b >> c;
		d = cmmdc(a, b);
		if (floor((double)c / d) == (double)c / d)
		{
			x = 0;
			y1 = (double)-a / b*x + (double)c / b;
			y2 = (double)a / b*x + (double)c / b;
			while ((y1 - floor(y1) > 0.000001) && (y2 - floor(y2) > 0.000001))
			{
				x = x + 1;
				y1 = (double)-a / b*x + (double)c / b;
				y2 = (double)a / b*x + (double)c / b;
				if ((x > 2000000000) || (y1 > 2000000000) || (y2 > 2000000000) || (y1 < -2000000000) || (y2 < -2000000000))
				{
					break;
				}
			}
			if (y1 - floor(y1) < 0.000001)
			{
				fout << x << " " << y1 << "\n";
			}
			else if (y2 - floor(y2) < 0.000001)
			{
				fout << -x << " " << y2 << "\n";
			}
		}
		else
		{
			fout << 0 << " " << 0 << "\n";
		}
	}
    return 0;
}