Cod sursa(job #487774)

Utilizator cristian9Cristian Zloteanu cristian9 Data 26 septembrie 2010 15:51:17
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include<stdio.h>
long a, b, s;

int functie(long x){
    long m, s=0;
    for(long j=5; j<=x; j+=5){
        if(j%25==0){
            if(j/25>1)
                s=s+(j/25)/5+2;
            else
                s=s+2;
        }
        else{
            s=s+1;
        }
    }
    //printf("%ld %ld %ld %ld\n", a, b, (a+b)/2, s);
    return s;

}

int main(){
    freopen ("fact.in", "r", stdin);
    freopen ("fact.out", "w", stdout);

    long p;

    scanf("%ld ", &p);

    if(p==1){
        printf("-1");
        return 0;
    }

    a=0, b=10000;
    /*printf("%ld ", functie(50));
    return 0;*/
    while(a<b){
        if(functie((a+b)/2)==p){
            s=(a+b)/2;
            printf("%ld ", (a+b)/2 - (s%5));
            return 0;
        }
        else{
            if(functie((a+b)/2)<p){
                a=(a+b)/2+1;
            }
            else{
                b=(a+b)/2-1;
            }
        }
    }

    printf("-1");

    return 0;
}