Advertisement
a53

kfact

a53
Feb 3rd, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. /// 25 -> 15511210043330985984000000
  4.  
  5. int nrcifre(int n)
  6. {
  7. int nr=0;
  8. while(n)
  9. ++nr,n/=10;
  10. return nr;
  11. }
  12.  
  13. int main()
  14. {
  15. int n,k;
  16. ifstream f("kfact.in");
  17. f>>n>>k;
  18. f.close();
  19. ofstream g("kfact.out");
  20. if(n==0)
  21. {
  22. g<<-1;
  23. return 0;
  24. }
  25. unsigned long long int MOD=10000000000,fact=1;
  26. for(int i=1;i<=n;++i)
  27. {
  28. /// g<<fact<<'*'<<i<<" = ";
  29. fact=fact*i;
  30. /// g<<fact<<endl;
  31. while(fact%10==0) /// Renunt la zerouri
  32. fact/=10;
  33. fact%=MOD;
  34. }
  35. int nrcif=nrcifre(fact);
  36. if(nrcif<k)
  37. {
  38. g<<-1;
  39. return 0;
  40. }
  41. for(int i=1;i<k;++i)
  42. fact/=10;
  43. g<<fact%10;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement