fork(1) download
  1. // DuckWuynh06
  2. // Cầu cho code con không bug
  3. // _oo0oo_
  4. // o8888888o
  5. // 88" . "88
  6. // (| -_- |)
  7. // 0\ = /0
  8. // ___/`---'\___
  9. // .' \| |// '.
  10. // / \||| : |||// \
  11. // / _||||| -:- |||||- \
  12. // | | \ - /// | |
  13. // | \_| ''\---/'' |_/ |
  14. // \ .-\__ '-' ___/-. /
  15. // ___'. .' /--.--\ `. .'___
  16. // ."" '< `.___\_<|>_/___.' >' "".
  17. // | | : `- \`.;`\ _ /`;.`/ - ` : | |
  18. // \ \ `_. \_ __\ /__ _/ .-` / /
  19. // =====`-.____`.___ \_____/___.-`___.-'=====
  20. // `=---='
  21. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. { _.-/`)
  23.   // / / )
  24.   .=// / / / )
  25.   //`/ / / / /
  26.   // / ` /
  27.  || /
  28.  \\ /
  29.   )) .'
  30.  // /
  31.   /
  32. // AMEN
  33. }
  34. uses math,sysutils;
  35. type bigNum=ansistring;
  36. type Num=string;
  37. type data=longint;
  38. type small=integer;
  39. type ssmall=byte;
  40. type ASCII=char;
  41. type huyenthoai=text;
  42. type ojt1=record
  43. val:ssmall;
  44. ch:ASCII;
  45. st:Num;
  46. end;
  47. type ojt=record
  48. null:ojt1;
  49. nill:ojt1;
  50. end;
  51. type obj1=record
  52. suc:ssmall;
  53. cu:ssmall;
  54. bus:ssmall;
  55. end;
  56. type obj=record
  57. wuynh:obj1;
  58. end;
  59. type ob=record
  60. duck:obj;
  61. end;
  62. const
  63. SUCCUBUS=10;
  64. BUSCUSUC=0;
  65. kha='bai3.inp';
  66. bruh='bai3.out';
  67. const
  68. NULL_CONST: ojt = (null:(val: 0;ch: '0';st:'';);nill:(val: 1; ch: '1';st:''));
  69. DUCK_CONST: ob = (duck: (wuynh: (suc: 10; cu: 2;bus:69)));
  70. var thich,cu:bigNum;
  71. bu:Num;
  72. nhac,ke:huyenthoai;
  73. function cmp(a,b:bigNum): small;
  74. begin
  75. while length(a)<length(b) do a:=NULL_CONST.null.ch+a;
  76. while length(b)<length(a) do b:=NULL_CONST.null.ch+b;
  77. if a = b then exit(NULL_CONST.null.val);
  78. if a > b then exit(NULL_CONST.nill.val);
  79. exit(-NULL_CONST.nill.val);
  80. end;
  81. function add(a,b : bigNum): bigNum;
  82. var sum, carry, i, x, y : small;
  83. c : bigNum;
  84. begin
  85. carry:=NULL_CONST.null.val;c:=NULL_CONST.nill.st;
  86. while length(a)<length(b) do a:=NULL_CONST.null.ch+a;
  87. while length(b)<length(a) do b:=NULL_CONST.null.ch+b;
  88. for i:=length(a) downto NULL_CONST.nill.val do
  89. begin
  90. x:= ord(a[i])-ord(NULL_CONST.null.ch);
  91. y:= ord(b[i])-ord(NULL_CONST.null.ch);
  92. sum:=x + y + carry;
  93. carry:=sum div DUCK_CONST.duck.wuynh.suc;
  94. c:=chr(sum mod DUCK_CONST.duck.wuynh.suc + ord(NULL_CONST.null.ch))+c;
  95. end;
  96. if carry>NULL_CONST.null.val then c:=NULL_CONST.nill.ch+c;
  97. add:=c;
  98. end;
  99. function sub(a,b:bigNum):bigNum;
  100. var c :bigNum;
  101. s,borrow,i :small;
  102. begin
  103. borrow:=NULL_CONST.null.val;c:=NULL_CONST.nill.st;
  104. while length(a)<length(b) do a:=NULL_CONST.null.ch+a;
  105. while length(b)<length(a) do b:=NULL_CONST.null.ch+b;
  106. for i:=length(a) downto NULL_CONST.nill.val do
  107. begin
  108. s:=ord(a[i])-ord(b[i])-borrow;
  109. if s<NULL_CONST.null.val then
  110. begin
  111. s:=s+DUCK_CONST.duck.wuynh.suc;
  112. borrow:=NULL_CONST.nill.val;
  113. end else borrow:=NULL_CONST.null.val;
  114. c:=chr(s+ord(NULL_CONST.null.ch))+c;
  115. end;
  116. while (length(c)>NULL_CONST.nill.val)and(c[NULL_CONST.nill.val]=NULL_CONST.null.ch) do delete(c,NULL_CONST.nill.val,NULL_CONST.nill.val);
  117. sub:=c;
  118. end;
  119. function multiply1(a:bigNum;b:data):bigNum;
  120. var i :small;
  121. carry,s :data;
  122. c,tmp :bigNum;
  123. begin
  124. c:=NULL_CONST.nill.st;
  125. carry:=NULL_CONST.null.val;
  126. for i:=length(a) downto NULL_CONST.nill.val do
  127. begin
  128. s:=(ord(a[i])-ord(NULL_CONST.null.ch)) * b + carry;
  129. carry:= s div DUCK_CONST.duck.wuynh.suc;
  130. c:=chr(s mod DUCK_CONST.duck.wuynh.suc + ord(NULL_CONST.null.ch))+c;
  131. end;
  132. if carry>NULL_CONST.null.val then str(carry,tmp) else tmp:=NULL_CONST.nill.st;
  133. multiply1:=tmp+c;
  134. end;
  135. function multiply2(a,b:bigNum):bigNum;
  136. var sum,tmp :bigNum;
  137. m,i,j :small;
  138. begin
  139. m:=-NULL_CONST.nill.val;sum:=NULL_CONST.nill.st;
  140. for i:=length(a) downto NULL_CONST.nill.val do
  141. begin
  142. m:=m+NULL_CONST.nill.val;
  143. tmp:=multiply1(b,ord(a[i])-ord(NULL_CONST.null.ch));
  144. for j:=NULL_CONST.nill.val to m do tmp:=tmp+NULL_CONST.null.ch;
  145. sum:=add(tmp,sum);
  146. end;
  147. multiply2:=sum;
  148. end;
  149. function bigDiv1(a:bigNum;b:data):bigNum;
  150. var s,i,hold:data;
  151. c:bigNum;
  152. begin
  153. hold:=NULL_CONST.null.val;s:=NULL_CONST.null.val; c:=NULL_CONST.nill.st;
  154. for i:=NULL_CONST.nill.val to length(a) do
  155. begin
  156. hold:=hold*DUCK_CONST.duck.wuynh.suc+ord(a[i])-ord(NULL_CONST.null.ch);
  157. s:=hold div b;
  158. hold:=hold mod b;
  159. c:=c+chr(s+ord(NULL_CONST.null.ch));
  160. end;
  161. while (length(c)>NULL_CONST.nill.val) and(c[NULL_CONST.nill.val]=NULL_CONST.null.ch) do
  162. delete(c,NULL_CONST.nill.val,NULL_CONST.nill.val);
  163. bigDiv1:=c;
  164. end;
  165. function bigMod1(a:bigNum;b:data):longint;
  166. var i,hold:data;
  167. begin
  168. hold:=NULL_CONST.null.val;
  169. for i:=NULL_CONST.nill.val to length(a) do
  170. hold:=(ord(a[i])-ord(NULL_CONST.null.ch)+hold*DUCK_CONST.duck.wuynh.suc) mod b;
  171. bigMod1:=hold;
  172. end;
  173. function bigDiv2(a,b:bigNum):bigNum;
  174. var c,hold :bigNum;
  175. kb :array[BUSCUSUC..SUCCUBUS]of bigNum;
  176. i,k :longint;
  177. begin
  178. kb[NULL_CONST.null.val]:=NULL_CONST.null.ch;
  179. for i:=NULL_CONST.nill.val to DUCK_CONST.duck.wuynh.suc do
  180. kb[i]:=add(kb[i-NULL_CONST.nill.val],b);
  181. hold:=NULL_CONST.nill.st;
  182. c:=NULL_CONST.nill.st;
  183. for i:=NULL_CONST.nill.val to length(a) do
  184. begin
  185. hold:=hold+a[i];
  186. k:=NULL_CONST.nill.val;
  187. while cmp(hold,kb[k])<>-NULL_CONST.nill.val do
  188. inc(k);
  189. c:=c+chr(k-NULL_CONST.nill.val+ord(NULL_CONST.null.ch));
  190. hold:=sub(hold,kb[k-NULL_CONST.nill.val]);
  191. end;
  192. while (length(c)>NULL_CONST.nill.val)and(c[NULL_CONST.nill.val]=NULL_CONST.null.ch) do delete(c,NULL_CONST.nill.val,NULL_CONST.nill.val);
  193. bigDiv2:=c;
  194. end;
  195. function bigMod2(a,b:bigNum):bigNum;
  196. var hold :bigNum;
  197. kb :array[BUSCUSUC..SUCCUBUS]of bigNum;
  198. i,k :data;
  199. begin
  200. kb[NULL_CONST.null.val]:=NULL_CONST.null.ch;
  201. for i:=NULL_CONST.nill.val to DUCK_CONST.duck.wuynh.suc do
  202. kb[i]:=add(kb[i-NULL_CONST.nill.val],b);
  203. hold:=NULL_CONST.nill.st;
  204. for i:=NULL_CONST.nill.val to length(a) do
  205. begin
  206. hold:=hold+a[i];
  207. k:=NULL_CONST.nill.val;
  208. while cmp(hold,kb[k])<>-NULL_CONST.nill.val do
  209. inc(k);
  210. hold:=sub(hold,kb[k-NULL_CONST.nill.val]);
  211. end;
  212. bigMod2:=hold;
  213. end;
  214. function cs2(n:bigNum):bigNum;
  215. var s,c:bigNum;
  216. begin
  217. s:=NULL_CONST.nill.st;
  218. while n<>NULL_CONST.null.ch do
  219. begin
  220. str(bigMod1(n,DUCK_CONST.duck.wuynh.cu),c);
  221. s:=c+s;
  222. n:=bigDiv1(n,DUCK_CONST.duck.wuynh.cu);
  223. end;
  224. exit(s);
  225. end;
  226. Procedure anhhoangtocnhucailonkhit;
  227. Begin
  228. Assign(nhac,kha);
  229. Reset(nhac);
  230. Assign(ke,bruh);
  231. Rewrite(ke);
  232. End;
  233. Procedure anhduckwuynhdeptraikhoaitoso1thegioi;
  234. Begin
  235. readln(thich);
  236. readln(bu);
  237. readln(cu);
  238. case bu of
  239. 'cong': write(cs2(add(thich,cu)));
  240. 'tru': write(cs2(sub(thich,cu)));
  241. 'nhan': write(cs2(multiply2(thich,cu)));
  242. 'chia': write(cs2(bigDiv2(thich,cu)));
  243. end;
  244. end;
  245. Procedure noithatdaydeoduadau;
  246. Begin
  247. Close(nhac);
  248. Close(ke);
  249. End;
  250. begin
  251. anhhoangtocnhucailonkhit;
  252. anhduckwuynhdeptraikhoaitoso1thegioi;
  253. noithatdaydeoduadau;
  254. end.
  255.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.pas:1: warning: missing program header
prog.pas:34: error: module/unit interface `math' could not be imported
stdout
Standard output is empty