function CycleFraction(a, b: integer): string;
begin
Result := (a div b).ToString;
a := a mod b;
if a = 0 then exit;
Result += ','; // разделитель
var k := Result.Length + 1;
var ost := new SortedList<integer, integer>;
ost.Add(a, k);
while True do
a *= 10;
Result += (a div b).ToString;
if ost.ContainsKey(a) then
var p := ost.Get(a);
Result := Result?[:p] + (a <> 0 ? '(' + Result?[p:] + ')' : ''.ToString);
exit
end
else
k += 1;
end;
var (a, b) := ReadInteger2('Введите числитель и знаменатель:');
CycleFraction(a, b).Println;
end.
1.12(10)=1100(2) 11.118(10)=1110110(2) 21.111(10)=11010010100(2)
2.15(10)=1111(2) 12.205(10)=11001101(2) 22.222(10)=11011110(2)
3.25(10)=11001(2) 13.394(10)=110001010(2) 23.333(10)=101001101(2)
4.36(10)=100100(2) 14.429(10)=110101101(2) 24.444(10)=110111100(2)
5.47(10)=101111(2) 15.533(10)=1000010101(2) 25.555(10)=1000101011(2)
6.58(10)=111010(2) 16.671(10)=1010011111(2) 26.666(10)=1010011010(2)
7.69(10)=1000101(2) 17.786(10)=1100010010(2) 27.777(10)=1010011010(2)
8.71(10)=1000111(2) 18.892(10)=1101111100(2) 28.888(10)=1010011010(2)
9.82(10)=1010010(2) 19.900(10)=1110000100(2) 29.999(10)=1111100111(2)
10.91(10)=1011011(2) 20.1684(10)=11010010100(2) 30.254(10)=11111110(2)
function CycleFraction(a, b: integer): string;
begin
Result := (a div b).ToString;
a := a mod b;
if a = 0 then exit;
Result += ','; // разделитель
var k := Result.Length + 1;
var ost := new SortedList<integer, integer>;
ost.Add(a, k);
while True do
begin
a *= 10;
Result += (a div b).ToString;
a := a mod b;
if ost.ContainsKey(a) then
begin
var p := ost.Get(a);
Result := Result?[:p] + (a <> 0 ? '(' + Result?[p:] + ')' : ''.ToString);
exit
end
else
begin
k += 1;
ost.Add(a, k);
end
end
end;
begin
var (a, b) := ReadInteger2('Введите числитель и знаменатель:');
CycleFraction(a, b).Println;
end.
1.12(10)=1100(2) 11.118(10)=1110110(2) 21.111(10)=11010010100(2)
2.15(10)=1111(2) 12.205(10)=11001101(2) 22.222(10)=11011110(2)
3.25(10)=11001(2) 13.394(10)=110001010(2) 23.333(10)=101001101(2)
4.36(10)=100100(2) 14.429(10)=110101101(2) 24.444(10)=110111100(2)
5.47(10)=101111(2) 15.533(10)=1000010101(2) 25.555(10)=1000101011(2)
6.58(10)=111010(2) 16.671(10)=1010011111(2) 26.666(10)=1010011010(2)
7.69(10)=1000101(2) 17.786(10)=1100010010(2) 27.777(10)=1010011010(2)
8.71(10)=1000111(2) 18.892(10)=1101111100(2) 28.888(10)=1010011010(2)
9.82(10)=1010010(2) 19.900(10)=1110000100(2) 29.999(10)=1111100111(2)
10.91(10)=1011011(2) 20.1684(10)=11010010100(2) 30.254(10)=11111110(2)