Cod sursa(job #1842602)
| Utilizator | Data | 7 ianuarie 2017 12:08:34 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 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 && p != 5)
{
while ( nf % x != 0 )
{
nf = nf * n;
nf = nf % x;
n = n + 1;
}
fout << n - 1 << "\n";
}
if (p == 5) fout << -1 << "\n";
else fout << 1 << "\n";
return 0;
}
