Pagini recente » Cod sursa (job #3287285) | Cod sursa (job #226154) | Cod sursa (job #3286826) | Cod sursa (job #1472256) | Cod sursa (job #2240319)
#include <bits/stdc++.h>
using namespace std;
ifstream f("progresie.in");
ofstream g("progresie.out");
bool inSeq(uint64_t x)
{
uint64_t sqx=sqrt(x);
if(sqx*sqx!=x) sqx++;
else return true;
return sqx*(sqx-1)+1<=x && x<sqx*sqx;
}
int main()
{
int T;
f>>T;
for(int N,R;T--;)
{
f>>N>>R;
bool found=false;
int k=1,x0;
while(!found)
{
uint64_t x=(k-1)*k+1;
x0=x;
int cnt=1;
while(cnt<N)
{
x+=R;
if(!inSeq(x)) break;
cnt++;
}
k++;
found=(cnt==N);
}
g<<x0<<'\n';
}
return 0;
}