1)определи основание системы счисления числа 162(8) . 2)переведи число 1022(8) в десятичную систему счисления. ответ: 1022(8)=ответ со степенью 3)запиши число 12542 в развёрнутом виде, начиная со старшего разряда.
M = [] n=20 base=2 for i in 0...(base**n) bin = i m[i]=[] for j in 0...n m[i][j] = bin % base bin/=base end end
start = 17 stop=729 min="22222222222222222222222222" s="" m.each do |ops| num = start s="" ops.each do |op| if op==0 num+=1 s+="1" else num*=2 s+="2" end if num >= stop then break end end # if (num == stop) then p s end if (num == stop) and (s.size<min.size) then min=s end end p min
procedure get_num(var m: bignum; var n: integer); var i := 0; s: string; begin write('Введите число = '); readln(s); s := trim(s); n := 0; for i := length(s) downto 1 do if s[i] in ['0'..'9'] then begin n := n + 1; m[n] := strtoint(s[i]); end; end;
function more(a, b: bignum; n_a: integer): boolean; var i: integer; f := false; begin for i := n_a downto 1 do begin if a[i] > b[i] then f := true else if a[i] < b[i] then f := false; if a[i] <> b[i] then break; end; more := f; end;
procedure show(m: bignum; n: integer); var i: integer; begin write('Вывод '); for i := n downto 1 do write(m[i]); writeln(); end;
begin get_num(a, n_a); get_num(b, n_b);
while (n_a >= n_b) and more(a, b, n_a) do begin if (a[n_a] > b[n_b]) then k := n_a - n_b else if n_a > n_b then k := n_a - n_b - 1 else k := 0;
for i := 1 to n_b do begin a[i + k] := a[i + k] - b[i]; if a[i + k] < 0 then begin for j := i + k to n_a - 1 do begin if a[j] >= 0 then break; a[j] := a[j] + 10; a[j + 1] := a[j + 1] - 1; end end; end; if a[n_a] = 0 then n_a := n_a - 1; end;
n=20
base=2
for i in 0...(base**n)
bin = i
m[i]=[]
for j in 0...n
m[i][j] = bin % base
bin/=base
end
end
start = 17
stop=729
min="22222222222222222222222222"
s=""
m.each do |ops|
num = start
s=""
ops.each do |op|
if op==0
num+=1
s+="1"
else
num*=2
s+="2"
end
if num >= stop then break end
end
# if (num == stop) then p s end
if (num == stop) and (s.size<min.size) then
min=s
end
end
p min
"1111121212221"
bignum = array[1..100] of integer;
var
a, b: bignum;
i, j, k, n_a, n_b: integer;
procedure get_num(var m: bignum; var n: integer);
var
i := 0;
s: string;
begin
write('Введите число = ');
readln(s);
s := trim(s);
n := 0;
for i := length(s) downto 1 do
if s[i] in ['0'..'9'] then begin
n := n + 1;
m[n] := strtoint(s[i]);
end;
end;
function more(a, b: bignum; n_a: integer): boolean;
var
i: integer;
f := false;
begin
for i := n_a downto 1 do
begin
if a[i] > b[i] then f := true
else if a[i] < b[i] then f := false;
if a[i] <> b[i] then break;
end;
more := f;
end;
procedure show(m: bignum; n: integer);
var
i: integer;
begin
write('Вывод ');
for i := n downto 1 do
write(m[i]);
writeln();
end;
begin
get_num(a, n_a);
get_num(b, n_b);
while (n_a >= n_b) and more(a, b, n_a) do
begin
if (a[n_a] > b[n_b]) then k := n_a - n_b
else if n_a > n_b then k := n_a - n_b - 1
else k := 0;
for i := 1 to n_b do
begin
a[i + k] := a[i + k] - b[i];
if a[i + k] < 0 then begin
for j := i + k to n_a - 1 do
begin
if a[j] >= 0 then break;
a[j] := a[j] + 10;
a[j + 1] := a[j + 1] - 1;
end
end;
end;
if a[n_a] = 0 then n_a := n_a - 1;
end;
show(a, n_a);
end.