Cod sursa(job #955956)

Utilizator PopConConstantin Popescu PopCon Data 1 iunie 2013 22:48:42
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;

ifstream in("factorial.in");
ofstream out("factorial.out");

int main()
{
    int p,n=0;
    int p_temp,n_temp;

    in>>p;

    while(p>20)
    {
        p_temp=2;
        n_temp=10;

        while((p_temp*10+1)<p)
            p_temp=p_temp*10+1;
            n_temp*=10;

        p-=p_temp;
        n+=n_temp;
    }

    if(p==0)
        out<<1;
    else if(p==20)
        out<<-1;
    else
        out<<(n+p*5);

    return 0;
}