SHARE
TWEET

Untitled

a guest Mar 4th, 2018 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. {$APPTYPE CONSOLE}
  84.  
  85. uses
  86.   Math;
  87.  
  88. const
  89.   MAXSIZE = 1000;
  90.  
  91. type
  92.   BigInt = record
  93.     size: integer;
  94.     number: array [1..MAXSIZE] of integer;
  95.   end;
  96.    
  97. var
  98.   n, m, res: BigInt;
  99.  
  100. procedure println(var x: BigInt);
  101. var
  102.   i: integer;
  103. begin
  104.   for i := x.size to MAXSIZE do
  105.     write(x.number[i]);
  106.   writeln;
  107. end;
  108.  
  109. procedure cin(var x: BigInt);
  110. var
  111.   i: integer;
  112.   s: string;
  113. begin
  114.   readln(s);
  115.   x.size := MAXSIZE - length(s) + 1;
  116.   for i := x.size to MAXSIZE do
  117.     x.number[i] := ord(s[i - x.size + 1]) - 48;
  118. end;
  119.  
  120. function add(n, m: BigInt): BigInt;
  121. var
  122.   i, temp: integer;
  123. begin
  124.   for i := MAXSIZE downto min(n.size, m.size) do begin
  125.     temp := result.number[i] + n.number[i] + m.number[i];
  126.     result.number[i] := temp mod 10;
  127.     result.number[i - 1] := temp div 10;
  128.   end;
  129.   result.size := min(n.size, m.size);
  130.   if (result.number[result.size - 1] > 0) then
  131.     dec(result.size);
  132. end;
  133.  
  134. function mult(n, m: BigInt): BigInt;
  135. var
  136.   i, j, index, temp: integer;
  137. begin
  138.   for i := 1 to MAXSIZE do
  139.     result.number[i] := 0;
  140.   for i := MAXSIZE downto n.size do
  141.     for j := MAXSIZE downto m.size do begin
  142.       index := i + j - MAXSIZE;
  143.       temp := result.number[index] + n.number[i] * m.number[j];
  144.       result.number[index] := temp mod 10;
  145.       inc(result.number[index - 1], temp div 10);
  146.     end;
  147.   i := 1;
  148.   while ((i < MAXSIZE) and (result.number[i] = 0)) do
  149.     inc(i);
  150.   result.size := i;
  151. end;
  152.  
  153. begin
  154.   assign(input, 'INPUT.TXT');
  155.   reset(input);
  156.   assign(output, 'OUTPUT.TXT');
  157.   rewrite(output);
  158.   cin(n);
  159.   cin(m);
  160.   res := mult(n, m);
  161.   println(res);
  162.   readln;
  163.   readln;
  164. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top