Cod sursa(job #175018)

Utilizator RoflmaoPatru Ovidiu Roflmao Data 9 aprilie 2008 14:56:19
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<fstream.h>
#include<iostream.h>
#include<math.h>
int main(void)
{
  fstream f,g;
  long int x=1,p,temp=0,i,coun=0,temp2=1;
  f.open("fact.in",ios::in);
  f>>p;
  f.close();
  while(x<p)
    x=x*5+1;
  x=(x-1)/5;
  g.open("fact.out",ios::out);
  if(p==0)
    g<<1;
  else
  {
    if(p%6==5||p%31==30||p%156==155||p%781==780)
      g<<-1;
    else
    {
      for(i=6;i<=x;i=(i*5)+1)
      {
	coun++;
	temp=temp+p/i;
      }
      g<<(p-temp)*5;
    }
  }
  return 0;
}