Pagini recente » Cod sursa (job #2291258) | Cod sursa (job #62418) | Cod sursa (job #608958) | Cod sursa (job #2023937) | Cod sursa (job #1907259)
#include <fstream>
#include <cmath>
using namespace std;
int t,n,r;
long long rez(int N, int R)
{
for(int i=0; ;++i)
{
long long start=1LL*i*(i+1)+1;
long long margin=i;
int isOK=1;
for(int it=1; it<N; it++)
{
long long low=start+1LL*it*R;
long long high=low+margin;
int j = (int)sqrt(low - 1);
long long lowi=1LL*j*(j+1)+1;
long long highi=1LL*(j+1)*(j+1);
if (high<lowi)
{
isOK=0;
break ;
}
if(low<lowi)
{
start+=lowi-low;
margin-=lowi-low;
}
else if(high>highi)
margin-=high-highi;
}
if (isOK)
return start;
}
}
int main()
{
ifstream f("progresie.in");
ofstream g("progresie.out");
f>>t;
while(t)
{
t--;
f>>n>>r;
g<<rez(n,r)<< "\n";
}
}