Cod sursa(job #2544603)
Utilizator | Data | 12 februarie 2020 11:54:33 | |
---|---|---|---|
Problema | Factorial | Scor | 15 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,k,km,n=1;
int main()
{
fin>>p;
if(p==0)fout<<"1";
else
{
for(int i=1;k<p;++i)
{
k+=i;
km-=i;
}
if(k==p)fout<<n;
else{
if(km==p)fout<<km;
else fout<<"-1";}
}
return 0;
}