fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef unsigned int Uint;
  5. #define N 78
  6. Uint DP=1;
  7. //RADIX == 10^LOG
  8. #define LOG 1
  9. #define RADIX 10
  10. typedef Uint Liczba[N+1];
  11.  
  12. void pisz( Liczba a, int ctrl){ Uint i;
  13. for( i=1; i<DP && !a[i]; i++ ) printf("%*s", LOG,"");
  14. printf("%*u", LOG, a[i]);
  15. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  16. putchar('.');
  17. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]);
  18. if( ctrl < 0 ) puts("");}
  19.  
  20. void plus( Liczba a, Liczba b){ // a[]:=a[]+b[]
  21. for( Uint c=0, i=N; i>0; i-- ){
  22. c += a[i]+b[i];
  23. a[i] = c % RADIX;
  24. c /= RADIX;}}
  25.  
  26. void minus( Liczba a, Liczba b ) { // a[]:=a[]-b[]
  27. for( Uint c=0, i=N; i>0; i-- ){
  28. c += b[i];
  29. if( a[i]<c ){
  30. a[i] = RADIX + a[i] - c; c=1; }
  31. else {
  32. a[i] -= c; c=0; }}}
  33.  
  34. void razyU( Liczba a, Uint b ) { // a[]:=a[] * b
  35. for( Uint c=0,i=N; i>0; i-- ){
  36. c += a[i]*b;
  37. a[i]= c % RADIX;
  38. c /= RADIX; }}
  39.  
  40. int podzielU( Liczba w, Liczba a, Uint b ) { // w[]:=a[] / b
  41. Uint z=0; // return w[] != 0
  42. for( Uint c=0, i=1; i<=N; i++ ) {
  43. c = c*RADIX+a[i];
  44. w[i]= c/b % RADIX; if( w[i] ) z=1;
  45. c = c - w[i]*b;}
  46. return z;}
  47.  
  48. void wstawU( Liczba a, Uint b ) { // a[]:= b
  49. Uint i;
  50. for( i=0; i<=N; i++ ) a[i]=0;
  51. i=DP;
  52. while( b ) {
  53. a[i--] = b%RADIX; b /= RADIX; }}
  54.  
  55. void atg( Liczba a, Uint x ) { // a[]:= atan( 1/x )
  56. Liczba px;
  57. wstawU( px, 1 ); podzielU( px, px, x );
  58. wstawU( a, 0 ); plus ( a, px );
  59. for( Uint n=1; ; n++){
  60. Liczba b;
  61. podzielU( px, px, x*x );
  62. if( ! podzielU( b, px, 2*n + 1 ) )
  63. break;
  64. if( n & 1 ) minus( a, b );
  65. else plus( a, b );}}
  66.  
  67. void silnia( Liczba a, Uint n ){ // a[]:= n!
  68. wstawU( a, 1 );
  69. while( n>1 )
  70. razyU( a, n-- );}
  71.  
  72. int main(void) {
  73. Liczba a1, a2;
  74. DP=1;
  75. atg ( a1, 5 );
  76. razyU( a1, 4 );
  77. atg ( a2, 239);
  78. minus( a1, a2 );
  79. razyU( a1, 4 );
  80. pisz ( a1, -1 );
  81.  
  82. DP=N;
  83. silnia(a1, 57 );
  84. pisz ( a1, -1 );
  85. return 0;
  86. }
  87.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
3.14159265358979323846264338327950288419716939937510582097494459230781640628624
 40526919504877216755680601905432322134980384796226602145184481280000000000000.