Advertisement
mehazava

Perevod

Nov 25th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6. {$IFDEF UNIX}{$IFDEF UseCThreads}
  7. cthreads,
  8. {$ENDIF}{$ENDIF}
  9. Classes
  10. { you can add units after this };
  11.  
  12. var
  13. inp,outp: text;
  14. x,y,aL,bL,i: longint;
  15. q,p,pplength,r,promL,cur: byte;
  16. a: array[0..1000] of longint;
  17. pPreob,prom: array[0..10] of byte;
  18. b,b1: array[0..10000] of longint;
  19. flag1: boolean;
  20. k: char;
  21.  
  22. procedure CountBL;
  23. begin
  24. bL:=10000;
  25. while b[bL]=0 do dec(bL);
  26. end;
  27.  
  28. procedure Preob(x: byte);
  29. var
  30. y: byte;
  31. begin
  32. y:=1;
  33. while x>q do begin
  34. prom[y]:=x mod q;
  35. x:=x div q;
  36. inc(y);
  37. end;
  38. prom[y]:=x;
  39. promL:=y;
  40. end;
  41.  
  42. begin
  43. assignfile(inp,'input.txt');
  44. assignfile(outp,'output.txt');
  45. rewrite(outp);
  46. reset(inp);
  47. //Reading inp
  48. readln(inp,p,q);
  49. aL:=0;
  50. repeat
  51. inc(aL);
  52. read(inp,k);
  53. a[aL]:=ord(k)-48;
  54. if a[aL]>10 then a[aL]-=7;
  55. until EOLn(inp);
  56. //Counting pPreob=(p)q and pplength
  57. x:=p;
  58. y:=1;
  59. while x>q do begin
  60. pPreob[y]:=x mod q;
  61. x:=x div q;
  62. inc(y);
  63. end;
  64. pPreob[y]:=x;
  65. pplength:=y;
  66. for y:=1 to pplength do write(pPreob[y]); //
  67. writeln; //
  68. //Clear b[]
  69. for x:=0 to 10000 do b[x]:=0;
  70. //Main cycle
  71. if (aL>1) then for x:=1 to (aL-1) do begin
  72. Preob(a[x]);
  73. r:=0;
  74. for y:=1 to promL do begin
  75. b[y]:=b[y]+r+prom[y];
  76. r:=b[y] div q;
  77. b[y]:=b[y] mod q;
  78. end;
  79. b[promL+1]+=r;
  80. //X pPreob
  81. CountBL;
  82. for i:=bL downto 1 do
  83. for y:=1 to bL do b1[y]:=b[y];
  84. for y:=1 to bL do b[y]:=0;
  85. for y:=1 to pplength do begin
  86. r:=0;
  87. for i:=1 to bL do begin
  88. cur:=y+i-1;
  89. b[cur]+=b1[i]*pPreob[y]+r;
  90. r:=b[cur] div q;
  91. b[cur]:=b[cur] mod q;
  92. end;
  93. b[cur+1]:=r;
  94. end;
  95. end;
  96. //Adding the last one
  97. Preob(a[x]);
  98. r:=0;
  99. for y:=1 to promL do begin
  100. b[y]:=b[y]+r+prom[y];
  101. r:=b[y] div q;
  102. b[y]:=b[y] mod q;
  103. end;
  104. b[promL+1]+=r;
  105. //Writing outp
  106. CountBL;
  107. for x:=bL downto 1 do begin
  108. if b[x]>9 then write(outp,chr(b[x]+55)) else
  109. write(outp,chr(b[x]+48));
  110. end;
  111. closefile(outp);
  112. closefile(inp);
  113. readln; //
  114. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement