Pagini recente » Cod sursa (job #2843230) | Cod sursa (job #2601570) | Cod sursa (job #1018168) | Cod sursa (job #398630) | Cod sursa (job #2681535)
#include<fstream>
#include<cmath>
#include<bitset>
#define lim 1500000000
using namespace std;
bitset<lim> sir;
ifstream f("progresie.in");
ofstream g("progresie.out");
int main()
{
bool gasit = false;
int t, n, r, i,dim = 1,j,aux,curent,ultimu;
for (i = 0; i < 1000; ++i)
{
for (j = 0; j < dim; ++j)
{
sir[i * dim + j] = 1;
sir[i * dim + j + dim] = 0;
}
dim++;
}
f >> t;
while (t)
{
gasit = false;
i = 0;
f >> n >> r;
while (!gasit) {
aux = n-1;
j = 1;
while (aux)
{
curent = j * r + i;
if (sir[curent] == 0)
break;
++j;
--aux;
}
if (aux == 0) {
gasit = true;
g << i+1 << '\n';
break;
}
i++;
if(sir[i] == 0)
i += sqrt(i-1) + 1;
}
--t;
}
return 0;
}