Pagini recente » Cod sursa (job #3183268) | Cod sursa (job #1949360) | Cod sursa (job #669864) | Cod sursa (job #581938) | Cod sursa (job #1182948)
#include<cstdio>
#include<cmath>
#define eps 0.000001
using namespace std;
int apartine(long long nr)//daca numarul apartine progresiei
{
int rad;
float rad_f;
rad = sqrt(nr);
rad_f = sqrtf(nr);
if((rad_f-rad)>eps)rad++;
if(rad*(rad-1)+1 <= nr)return 1;
return 0;
}
long long start(int N, int R)
{
long long V, E, k=2;
long long rad;
int i;
for(;;)//sau E+=valoare
{
V=(k-1)*(k-2)+1;
// printf("V=%d\n",V);
//V++;
E = V;
if(V==3)
{
int q=3;
}
while(!apartine(V+R))
{
V++;
E=V;
for(i=1; i<=N; i++)
{
if(!apartine(E))break;
E += R;
}
if(i==N+1)return V;
}
k++;
}
}
int main()
{
/* progresie care contine k elemente, nu contine k elemente, contine k+1 elemente,
nu contine k+1 elemente
*/
int T, N, R, k=0, nr=1, i, j;
long long V;
freopen("progresie.in","r",stdin);
freopen("progresie.out","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&N,&R);
printf("%lld\n", start(N,R));
}
return 0;
}