SPOJ FCTRL2 - Small factorials Solution

 Solution in C++:

 ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include<iostream>
    2. using namespace std;
    3. int main()
    4. {
    5.  
    6. int n,temp,ar[5000],i,j,c,v,t;
    7. cin>>t;
    8. while(t--)
    9. {
    10. while(cin>>n)
    11. {
    12. ar[0]=1;
    13. c=1;
    14. temp=0;
    15. for(i=1; i<=n; i++)
    16. {
    17. for(j=0; j<c; j++)
    18. {
    19. v=ar[j]*i+temp;
    20. ar[j]=v%10;
    21. temp=v/10;
    22. }
    23. while(temp>0)
    24. {
    25. ar[c]=temp%10;
    26. temp=temp/10;
    27. c++;
    28. }
    29. }
    30.  
    31. for(i=c-1; i>=0; i--)
    32. {
    33. cout<<ar[i];
    34. }
    35. cout<<endl;
    36.  
    37. }
    38. }
    39. }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

    Powered by Blogger.