var simple: List<integer> := new List<integer>; i, n, p: integer; m: longint;
begin read(n); for i := 2 to n do begin m := 1; foreach s: integer in simple do m := m * i mod s; if m > 0 then begin simple.Add(i); // write(i, ' '); end; end; writeln(); foreach s: integer in simple do begin if Math.Pow(2, s) - 1 <= longint.MaxValue then begin m := round(Math.Pow(2, s) - 1); if (m <= n) and simple.Contains(m) then write(m, ' '); end; end; end.
1 votes Thanks 0
cccc1808
function prost (x : integer) : boolean; var i : integer; r : boolean; begin i := 2; r := true; While (i <= x div 2) and (r) do begin if x mod i = 0 then r := false; i := i +1; end; Result := r; end;
var i,n : integer; t : text; begin readln (n); assign (t,'file.txt'); rewrite (t); for i := 2 to n do begin if prost(i) then write (t,i+' '); end; close (t); end.
Answers & Comments
System.Collections.Generic,
System;
var
simple: List<integer> := new List<integer>;
i, n, p: integer;
m: longint;
begin
read(n);
for i := 2 to n do
begin
m := 1;
foreach s: integer in simple do
m := m * i mod s;
if m > 0 then begin
simple.Add(i);
// write(i, ' ');
end;
end;
writeln();
foreach s: integer in simple do
begin
if Math.Pow(2, s) - 1 <= longint.MaxValue then begin
m := round(Math.Pow(2, s) - 1);
if (m <= n) and simple.Contains(m) then
write(m, ' ');
end;
end;
end.
var
i : integer;
r : boolean;
begin
i := 2;
r := true;
While (i <= x div 2) and (r) do
begin
if x mod i = 0 then
r := false;
i := i +1;
end;
Result := r;
end;
var
i,n : integer;
t : text;
begin
readln (n);
assign (t,'file.txt');
rewrite (t);
for i := 2 to n do
begin
if prost(i) then
write (t,i+' ');
end;
close (t);
end.