Cod sursa(job #2067378)

Utilizator StepHoria Stefan Step Data 16 noiembrie 2017 12:12:26
Problema GFact Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("gfact.in");
ofstream g("gfact.out");

int p;

int desc (int n)
{
	int nr=0;
	while (n>=p)
	{
		nr+=n/p;
		n/=p;
	}
	return nr;
}

int caut (int x)
{
	int pas=1<<30,r=0;
	while (pas!=0)
	{
		if (desc(r+pas)<x)
			r+=pas;
		pas/=2;
	}
	return r+1;
}

int main()
{
	int i,x,q;
	f>>p>>q;
	x=caut(q);
	g<<x;
    return 0;
}