end_num = 79 for n in 1..5 for i in 0..2**n-1 s = ("000000000000000000000000000000" + i.to_s(2))[-n..-1] start_num = 7 log = start_num.to_s for k in 0..s.size-1
start_num, log = f0(start_num, log) if s[k] == "0" start_num, log = f1(start_num, log) if s[k] == "1" # break if start_num > end_num end # p [start_num, log, s, n] if start_num == end_num then log += " = " + end_num.to_s p log end end end
vadimpopov88
25.01.2022
1. Вот так это пишется с функцией
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 function IsPrime(n:integer):boolean; begin if n<4 then Result:=True else begin var found:= (n mod 2 = 0); var p:=3; while (not found) and (sqr(p)<=n) do begin found:=(n mod p = 0); p+=2 end; Result:=not found end end;
begin Writeln('k=',ArrRandom(ReadInteger('n='),1,999).Println. Where(x->IsPrime(x)).Count) end.
// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 procedure IsPrime(n:integer; var res:boolean); begin if n<4 then res:=True else begin var found:= (n mod 2 = 0); var p:=3; while (not found) and (sqr(p)<=n) do begin found:=(n mod p = 0); p+=2 end; res:=not found end end;
begin var a:=ArrRandom(ReadInteger('n='),1,999); a.Println; var k:=0; var prime:boolean; foreach var e in a do begin IsPrime(e,prime); if Prime then Inc(k) end; Writeln('k=',k) end.
#Ruby22
def f0(number, log)
return [number * number, "(" + log + ")^2 "]
end
def f1(number, log)
return [number - 2, log + " - 2"]
end
end_num = 79
for n in 1..5
for i in 0..2**n-1
s = ("000000000000000000000000000000" + i.to_s(2))[-n..-1]
start_num = 7
log = start_num.to_s
for k in 0..s.size-1
start_num, log = f0(start_num, log) if s[k] == "0"
start_num, log = f1(start_num, log) if s[k] == "1"
# break if start_num > end_num
end
# p [start_num, log, s, n]
if start_num == end_num then
log += " = " + end_num.to_s
p log
end
end
end