fork(2) download
  1. #include<iostream>
  2. #include<malloc.h>
  3. #define MAX_SIZE 80
  4. using namespace std;
  5.  
  6. int current;
  7. void proMul(int* a, int num)
  8. {
  9. int tempc=0;
  10. int temp=0;
  11. while(tempc<=(current-1))
  12. {
  13. int x= (*(a+tempc)*num)+temp;
  14.  
  15. *(a+tempc)= x%10;
  16. temp= x/10;
  17. tempc++;
  18.  
  19. }
  20. tempc--;
  21.  
  22. while(temp>0)
  23. {
  24. tempc++;
  25. *(a+tempc) = temp%10;
  26. temp/=10;
  27. }
  28. current = tempc+1;
  29.  
  30. }
  31.  
  32. void printa(int* ans)
  33. {
  34. int temp= current-1;
  35. while(temp>=0)
  36. {
  37. cout<<*(ans+temp);
  38. temp--;
  39. }
  40. cout<<endl;
  41.  
  42. }
  43.  
  44. void fac(int num)
  45. {
  46. // int ans[MAX_SIZE]={0};
  47. int i;
  48. int* ans= (int*) (malloc(MAX_SIZE* sizeof(int)));
  49. for(i=0;i<MAX_SIZE;i++)
  50. *(ans+i) = 0;
  51. *ans= 1;
  52. current=1;
  53. while(num>1)
  54. { proMul(ans, num);
  55. num--;
  56. }
  57. printa(ans);
  58.  
  59. }
  60.  
  61. int main()
  62. {
  63. int T;
  64. cin>>T;
  65. int x;
  66. while(T--)
  67. {
  68. cin>>x;
  69. fac(x);
  70.  
  71. }
  72. return 0;
  73. }
Success #stdin #stdout 0s 2988KB
stdin
100
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
1
2
5
3
stdout
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6
1
2
120
6