Cod sursa(job #2240319)
Utilizator | Neacsu Stefan GiihuoTihufi | Data | 13 septembrie 2018 08:23:18 |
---|---|---|---|
Problema | Progresie | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva ICPC | Marime | 0.74 kb |
#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;
}