Cod sursa(job #1056707)

Utilizator bghimisFMI Ghimis Bogdan bghimis Data 14 decembrie 2013 13:28:59
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>
#include <queue>
using namespace std;

ifstream in ("cifre4.in");
ofstream out("cifre4.out");

long long bfs (int n, int k)
{
	queue<int> myQueue;
	myQueue.push(2);
	myQueue.push(3);
	myQueue.push(5);
	myQueue.push(7);

	while (true)
	{
		long long nr = myQueue.front();
		myQueue.pop();

		if (nr > 5 * 1000000)
			break;

		myQueue.push(nr * 10 + 2);
		myQueue.push(nr * 10 + 3);
		myQueue.push(nr * 10 + 5);
		myQueue.push(nr * 10 + 7);

		if (nr % k == n)
			return nr;
	}

	return -1;
}

int main()
{
	out << bfs (51,1123);
}