fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. #define N 1000
  6. #define BUFF10 (N * 10)
  7. #define BIT 31
  8. #define MASK 0x7fffffff
  9.  
  10. #define SIGN(x) (((x) >> (BIT - 1)) ? 1 : 0)
  11. typedef unsigned int uintN[N];
  12.  
  13. void shift_div(int *mod, uintN q) {
  14. int cy, i;
  15.  
  16. cy = 0;
  17. for (i = 0; i < N; i++) {
  18. q[i] = q[i] << 1;
  19. if (cy)
  20. q[i] = q[i] | 0x01;
  21. cy = (q[i] >> BIT);
  22. q[i] = q[i] & MASK;
  23. }
  24. *mod = *mod << 1;
  25. if (cy)
  26. *mod = *mod | 0x01;
  27. }
  28.  
  29. void copy_uintN(uintN a, uintN b) {
  30. int i;
  31. for (i = 0; i < N; i++)
  32. a[i] = b[i];
  33. }
  34.  
  35. void div10(uintN n, uintN q, int *mod) {
  36. int i;
  37. copy_uintN(q, n);
  38. *mod = 0;
  39. for (i = 0; i < N * BIT; i++) {
  40. shift_div(mod, q);
  41. if (*mod >= 10) {
  42. q[0] = q[0] | 0x01;
  43. *mod = *mod - 10;
  44. }
  45. }
  46. }
  47.  
  48. int iszero_uintN(uintN n) {
  49. int i;
  50. for (i = 0; i < N; i++)
  51. if (n[i] != 0)
  52. return 0;
  53. return 1;
  54. }
  55.  
  56. void output10(uintN m) {
  57. int mod10[BUFF10];
  58. uintN q, n;
  59. int i, mod;
  60.  
  61. copy_uintN(n, m);
  62. for(i = 0;;) {
  63. div10(n, q, &mod);
  64. if (iszero_uintN(q) && mod == 0)
  65. break;
  66. mod10[i++] = mod;
  67. copy_uintN(n, q);
  68. }
  69. i--;
  70. if (i < 0) {
  71. putchar('0');
  72. return;
  73. }
  74. for (;i >= 0; --i)
  75. putchar('0' + mod10[i]);
  76. }
  77.  
  78. /*---------------------------------------------------------*/
  79. #define M 1492
  80. uintN p;
  81. int main(int argc, char *argv[])
  82. {
  83. int i, k;
  84.  
  85. for (i = 0, k = M; k >= BIT; i++, k -= BIT)
  86. p[i] = MASK;
  87. for (; k > 0; --k) {
  88. p[i] = p[i] << 1;
  89. p[i] |= 1;
  90. }
  91. output10(p);
  92. return 0;
  93. }
  94. /* end */
  95. /*
  96. 13701039886888296385792026546984710153720318703254
  97. 23000940460860343397025412629773580354722132225361
  98. 78332618776544677802340994331802617030289730620773
  99. 45586268707014252081678618940157309212290213490891
  100. 47825786665212943572588474466504897797632395115650
  101. 18222861530279071623083004583441915452328553554240
  102. 54950903888363366272596653369828411329981748170778
  103. 17721668107944249347540702860431744661471426170000
  104. 00683802170035386251696025540573107514389504720895
  105. */
  106.  
Time limit exceeded #stdin #stdout 5s 2896KB
stdin
Standard input is empty
stdout
Standard output is empty