Virtual Object
::
Programs
:: Период дроби |
||||
Наша кнопка |
||||
Период дроби {$APPTYPE CONSOLE} var a:array [1..1000] of 0..9; f:array [0..10000] of longint; num,denum,count,n,m,x:longint; procedure write_now(t:longint); var i:longint; begin write(num div denum); if t=-1 then begin if n<>0 then write(′.′); for i:=1 to count do write(a[i]); end else if t<>0 then begin write(′.′); for i:=1 to t-1 do write(a[i]); write(′(′); for i:=t to count do write(a[i]); write(′)′); end; halt; end; begin assign(input,′input.txt′); reset(input); assign(output,′output.txt′); rewrite(output); read(num,denum); m:=denum; n:=num mod denum; count:=0; x:=0; f[0]:=-1; repeat while (n<>0)and(n<m)and(f[n]=0) do begin inc(count); f[n]:=count; n:=n*10; end; if n<m then x:=f[n] else begin a[count]:=n div m; n:=n mod m; end; until x<>0; write_now(x); end. |
||||
Object © 2004 - 2005. All rights reserved. |