Pagini recente » Cod sursa (job #1447323) | Cod sursa (job #396688) | Cod sursa (job #3241249) | Cod sursa (job #2945841) | Cod sursa (job #1439340)
// 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 long t, n, r, ok, i, sav, inceput = 1, lg = 1;
int bun(long long x)
{
long 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; inceput = 1;
lg = 1;
while (ok == 0)
{
long long j = inceput;
ok = 1;
for (int j2 = 2; j2 <= n; j2++)
{
if (bun(j+(j2-1)*r) == 0)
{
ok = 0;
break;
}
}
if (ok == 1)
{
sav = j;
break;
}
inceput += lg * 2;
lg++;
}
g << sav << '\n';
}
f.close();
g.close();
return 0;
}