Cod sursa(job #1439330)

Utilizator liisLIIS-Horia-Vlad-Denis liis Data 22 mai 2015 10:03:09
Problema Progresie Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 1 kb
// progresie.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <fstream>
#include <math.h>

using namespace std;
ifstream f("progresie.in");
ofstream g("progresie.out");


long t, n, r, ok, i, sav, inceput = 1, lg = 1;

int bun(long x)
{
	long k = sqrt(x);
	if (k*k < x) k++;
	if (x >= k * (k - 1) + 1 && x <= k*k)
		return 1;
	return 0;
}

//int _tmain(int argc, _TCHAR* argv[])
int main()
{
	f >> t;
	for (i = 1; i <= t; i++)
	{
		f >> n >> r;
		ok = 0;
		while (ok == 0)
		{
			int j = inceput;
	//		for (int j = inceput; j <= inceput + lg - 1; j++)
		//	{
				ok = 1;
				for (int j2 = 1; j2 <= n; j2++)
				{
					if (bun(j+(j2-1)*r) == 0)
					{
						ok = 0;
						break;
					}
				}/*
				if (ok == 1)
				{
					sav = j;
					break;
				}*/
	//		}
				if (ok == 1)
				{
					sav = j;
					break;
				}
			inceput += lg * 2;
			lg++;
		}
		g << sav << '\n';
	}


	f.close();
	g.close();
	return 0;
}