Pagini recente » Cod sursa (job #975177) | Cod sursa (job #2654621) | Cod sursa (job #1960292) | Cod sursa (job #2390309) | Cod sursa (job #1056205)
#include <iostream>
using namespace std;
#include <fstream>
#include <ctime>
int sir(int x)
{
int n=1;
bool ok=true;
while(n*n<x)
n++;
n--;
while(ok)
{
if(x>n*n&& x<=n*(n+1))
ok=false;
else
/*if(x>(n-1)*n && x<=n*n)
break;
else
n++;*/
break;
}
return ok;
}
int main()
{
ifstream fin("progresie.in");
ofstream fout("progresie.out");
int t;
fin>>t;
for(int i=0;i<t;i++)
{
int n,r;
fin>>n>>r;
bool ok=false;
int j=0,x1=1,x2=1;
while(!ok)
{
if(sir(x2))
{
j++;
if(j==n)
ok=true;
else
x2+=r;
}
else
{
x1+=1;
x2=x1;
j=0;
}
}
for(int i=0;i<n-1;i++)
x2-=r;
fout<<x2<<"\n";
}
}