Cod sursa(job #1842575)

Utilizator shantih1Alex S Hill shantih1 Data 7 ianuarie 2017 11:29:01
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int n, i;
long long x=1, nf, p;
int main() {
    
    fin >> p;
    
    for (i = 1; i <= p; i++)
        x *= 10;
    
    nf = 1;
    n = 1;
    
    if ( p > 0 )
    {
        while ( nf % x != 0 )
        {
        
            nf = nf * n;
            nf = nf % x;
            n = n + 1;
        }
        
        fout << n - 1 << "\n";
    }
    
    else fout << 1 << "\n";
    
    return 0;
}