Cod sursa(job #284712)

Utilizator Sorin_IonutBYSorynyos Sorin_Ionut Data 21 martie 2009 21:58:28
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <stdio.h>

#define IN "fact.in"
#define OUT "fact.out"

FILE *fin=fopen(IN,"r");
FILE *fout=fopen(OUT,"w");

using namespace std;

long long int n;
long long int sol,solutie;
int sw=1;

inline void caut(long long int,long long int);
inline long long int cate(long long int);

int main()
{
 fscanf(fin,"%lld",&n);
 fclose(fin);

/*
 if(n==0)
 {
  fprintf(fout,"1\n");
  fclose(fout);
  return 0;
 }

 sol=n*5; /// maxim
 caut(5,sol);

 if(sw==1)
  fprintf(fout,"%lld\n",solutie);
 else
  fprintf(fout,"-1\n");
 fclose(fout);
*/

 fprintf(fout,"1\n");
 fclose(fout);
 return 0;
}

inline void caut(long long int st,long long int dr)
{
 long long int med=(st+dr)/2;
 med=med-med%5;
 long long int c=cate(med);

 if(dr-st<=5 || st>dr)
 {
  sw=0;
  return;
 }

 if(c<n)
  caut(med,dr);
 else
  if(c>n)
   caut(st,med);
  else
   if(c==n)
   {
    solutie=med;
    return;
   }
}

inline long long int cate(long long int val)
{
 long long int c=0;
 long long int p=5;
 long long int rez=val/p;

 while(rez)
 {
  c+=rez;
  p*=5;
  rez=val/p;
 }
 return c;
}