Cod sursa(job #2914194)

Utilizator emberlustAlbuica Lucian Ionut emberlust Data 19 iulie 2022 11:34:21
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<iostream>
#include<fstream>
#include<cmath>

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