1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シクシク素数列Advent Calendar 2018

Day 19

シクシク素数列 (Pascal)

Last updated at Posted at 2018-12-18
シクシク素数列 https://qiita.com/advent-calendar/2018/4949prime-series
Crystal https://qiita.com/cielavenir/items/4c95fdf14b7a247e51e0
Kuin https://qiita.com/cielavenir/items/60993a2b2885690a3a4a
Swift https://qiita.com/cielavenir/items/db4c93532a53bfa33ac2
Kotlin https://qiita.com/cielavenir/items/f3ccdd5ebf245aba417c
Pascal https://qiita.com/cielavenir/items/4c962db6825d9a5eb511
4949.pas
program sksk;
var i,n,cnt: longint;

function isqrt(n: longint): longint;
var
	x: longint;
	y: longint;
begin
	if(n<=0) then
		isqrt:=0
	else if(n<4) then
		isqrt:=1
	else begin
		x:=0;
		y:=n;
		while((x<>y) and (x+1<>y)) do begin
			x:=y;
			y:=(n div y+y) div 2;
		end;
		isqrt:=x;
	end;
end;

function isPrime(i: longint): boolean;
var
	j: longint;
begin
	isPrime:=true;
	if i<2 then isPrime:=false;
	for j:=2 to isqrt(i) do begin
		if(i mod j < 1) then
			isPrime:=false;
	end;
end;

function is4949(i: longint): boolean;
begin
	if(i <= 0) then
		is4949:=false
	else if( (i mod 10 = 4)or(i mod 10 = 9) ) then
		is4949:=true
	else
		is4949:=is4949(i div 10);
end;

begin
	read(n);
	i:=2;
	cnt:=0;
	while(cnt<n) do begin
		if(is4949(i) and isPrime(i)) then begin
			write(i);
			if(cnt < n - 1) then
				write(',')
			else
				writeln();
			cnt:=cnt + 1;
		end;
		i:=i + 1;
	end;
end.
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?