fork download
  1. var c:array[0..100,0..100]of longint;
  2. fi,fo:text;
  3. n,k:longint;
  4. xau:string;
  5.  
  6. function t0(x:longint):longint;
  7. var i,t:longint;
  8. begin
  9. t:=0;
  10. for i:=1to x do
  11. if xau[i]='0' then inc(t);
  12. exit(t);
  13. end;
  14.  
  15. function pht(n:longint):string;
  16. var x:string;
  17. begin
  18. x:='';
  19. while n<>0 do
  20. begin
  21. if n mod 2=0 then x:='0'+x
  22. else x:='1'+x;
  23. n:=n div 2;
  24. end;
  25. exit(x);
  26. end;
  27.  
  28. procedure lam;
  29. var j,t,i:longint;
  30. kq,l:longint;
  31. begin
  32. while not eof(fi)do
  33. begin
  34. kq:=0;
  35. readln(fi,n,k);
  36. xau:=pht(n);
  37. l:=length(xau);
  38. t:=t0(l);
  39. if (t=k) then inc(kq);
  40. if k=1 then inc(kq);
  41. if (n=0)then
  42. begin
  43. if k=1 then writeln(fo,'1')
  44. else writeln(fo,'0');
  45. continue;
  46. end;
  47. for i:=k to l-2 do
  48. kq:=kq+c[i,k];
  49. t:=0;
  50. for i:=2to l-1 do
  51. if xau[i]='1' then
  52. begin
  53. t:=t0(i);
  54. if t>k then break
  55. { else
  56.   if t=k then
  57.   begin
  58.   for j:=i+1 to l do
  59.   if xau[i]='0' then break;
  60.   inc(kq,1);
  61.   end}
  62. else
  63. if t<k then
  64. kq:=kq+c[l-i,k-t-1];
  65. end;
  66. writeln(fo,kq);
  67. end;
  68. end;
  69.  
  70. procedure tohop;
  71. var i,j:longint;
  72. begin
  73. c[0,0]:=1;
  74. for i:=1to 32 do
  75. for j:=0 to i do
  76. c[i,j]:=c[i-1,j]+c[i-1,j-1];
  77. end;
  78.  
  79. begin
  80. assign(fi,'t.inp');reset(fi);
  81. assign(fo,'t.out');rewrite(fo);
  82. tohop;
  83. lam;
  84. close(fi);close(fo);
  85. end.
  86.  
  87.  
Runtime error #stdin #stdout 0s 316KB
stdin
Standard input is empty
stdout
Runtime error 2 at $08048493
  $08048493