Cod sursa(job #198926)

Utilizator TrumpCardPopescu Silviu TrumpCard Data 16 iulie 2008 10:23:24
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h> 
#include <math.h>
   int main()     
   {    
       freopen("fact.in", "r", stdin);    
       long P;    
       scanf("%ld", &P);    
       fclose(stdin);    
       freopen("fact.out", "w", stdout);    
       if (P==0) printf("%d",1);
       else {unsigned long long j=1, i=2;
             while(j%(unsigned long long)pow(5,P)) {j=j*i;i++;}
             while(P){j=j/5;P--;}
             if(j%5==0) printf("%d",-1);
             else printf("%ld", i-1);
            }
       fclose(stdout);    
       return 0;    
   }