Pagini recente » Cod sursa (job #169099) | Cod sursa (job #1990872) | Cod sursa (job #31595) | Cod sursa (job #1268862) | Cod sursa (job #1439330)
// 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;
}