Cod sursa(job #2445486)

Utilizator R3v1v3RAlexe Paul R3v1v3R Data 4 august 2019 12:09:18
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>

using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int main()
{
    int n,b,i,f=1,j,c=0,x,p;
    for(i=1; i<=5; i++)
    {
    in>>n;
    in>>b;
    p=1;
    f=1;
    c=0;
    for(j=1; j<=n; j++)
    f=f*j;
    while(f!=0)
    {
    c=c+p*(f%b);
    p=p*10;
    f=f/b;
    }
    x=c%10;
    while(x==0)
    {
    x=c%10;
    if(x!=0)
    c=c/10;
    }
    out<<c%10<<endl;
    }
    return 0;
}