Pagini recente » Cod sursa (job #1938669) | Cod sursa (job #103248) | Cod sursa (job #799522) | Cod sursa (job #1061881) | Cod sursa (job #1439329)
// 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)
{
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)
break;
inceput += lg * 2;
lg++;
}
g << sav << '\n';
}
f.close();
g.close();
return 0;
}