Cod sursa(job #1384890)

Utilizator sorincusmareIacob Sorin sorincusmare Data 11 martie 2015 15:07:21
Problema GFact Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.3 kb
#include <fstream>

using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int fct(int b,int p){
int nr=0;
while (b>=p)
{
nr+=b/p;
b/=p;
}
return nr;
}
int main()
{
 int p,b,i,pas,q;
 f>>p>>q;
 pas=1<<30;
 i=0;
 while(pas!=0){
    if(fct(i+pas,p)<q)
        i+=pas;
    pas/=2;
 }
 b=1+i;
 g<<b;
}