Pagini recente » Cod sursa (job #1023936) | Cod sursa (job #550047) | Istoria paginii utilizator/ulbs_ureche_toncu_cotofana | Cowfood | Cod sursa (job #2632066)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("progresie.in");
ofstream fout("progresie.out");
bool isIn(long long x)
{
int p = sqrt(x);
if(p * p == x)
return true;
if(x > p * (p + 1))
return true;
return false;
}
void solve()
{
int n, r;
fin >> n >> r;
for(int i = 1; ; ++i)
{
for(long long j = i * (i - 1) + 1; j <= i * i; ++j)
{
long long act = j;
bool ok = true;
for(int it = 2; it <= n && ok; ++it)
{
act += r;
if(!isIn(act))
ok = false;
}
if(ok == false)
continue;
if(ok == true)
{
fout << j << '\n';
return ;
}
}
}
}
main()
{
int t;
fin >> t;
for(; t; --t)
solve();
}