Cod sursa(job #2681535)

Utilizator trz59lollMurariu Iulian trz59loll Data 5 decembrie 2020 19:07:20
Problema Progresie Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.79 kb
#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;
}