Cod sursa(job #2914228)

Utilizator emberlustAlbuica Lucian Ionut emberlust Data 19 iulie 2022 13:49:41
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb

// Online C Compiler - Build, Compile and Run your C programs online in your favorite browser

#include<iostream>
#include<fstream>
#include<cmath>

int main()
{
    std::ifstream f("fact.in");
    unsigned int p;
    f>>p;
    f.close();
        
    unsigned long int fact = 1;
    unsigned long int ctr = 2;
        
    while(fact%(unsigned long int)pow(10,p) != 0)
    {
        fact = (fact * ctr%(unsigned long int)pow(10,p+1))%(unsigned long int)pow(10,p+1);
        ctr++;
    }
    
    std::ofstream of("fact.out");
    
    if(fact%(unsigned long int)pow(10,p+1)!=0)
    {
        of<<ctr-1;
    }
    else
    {
        of<<-1;
    }
    std::cout<<ctr-1<<std::endl;
    std::cout<<fact;
    of.close();
    
    return 0;
}