Var ar:array[1..n] of integer; ar2:array[1..n] of integer; i,k:integer;
function prost(a:integer):boolean; var i:integer; b:boolean; begin b:=true; for i:=2 to a div 2 do if a mod i=0 then begin; b:=false; break; end; if a=1 then b:=false; prost:=b; end;
begin; randomize; k:=0; for i:=1 to n do begin; ar[i]:=random(101); write(ar[i]:4); end; writeln; for i:=1 to n do if prost(ar[i]) then begin; inc(k); ar2[k]:=ar[i]; write(ar2[k]:4); end; end.
4094
Объяснение:
Function newstr1(str As String, n As Integer) As String
Dim i As Integer
For i = 1 To n
str = Replace(str, "A", "BC")
str = Replace(str, "B", "AC")
str = Replace(str, "CC", "AD")
Next
newstr1 = str
End Function
Function chrcount(str1 As String, str2 As String) As Integer
Dim str() As String
str = Split(str1, str2)
chrcount = UBound(str, 1)
End Function
=chrcount(newstr1("AA";11);"D")
Excel VBA
P.S.
Для номера процедуры равного i, количество символов "D" вычисляется по формуле D(i)=2*2^i-2