0
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.

シクシク素数列 (Kuin)

Last updated at Posted at 2018-12-20
シクシク素数列 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.kn
func isqrt(n: int): int
	if(n <= 0)
		ret 0
	end if
	if(n < 4)
		ret 1
	end if
	var x: int :: 0
	var y: int :: n
	while(x <> y & x + 1 <> y)
		do x :: y
		do y :: (n / y + y) / 2
	end while
	ret x
end func

func isPrime(i: int): bool
	if(i < 2)
		ret false
	end if
	for j(2, @isqrt(i))
		if(i % j < 1)
			ret false
		end if
	end for
	ret true
end func

func is4949(i: int): bool
	if(i <= 0)
		ret false
	end if
	if(i % 10 = 4 | i % 10 = 9)
		ret true
	end if
	ret @is4949(i / 10)
end func

func main()
	var n: int :: 0
	var _: bool
	do n :: cui@input().toInt(&_)
	var i: int :: 2
	var cnt: int :: 0
	while(cnt < n)
		if(@is4949(i) & @isPrime(i))
			do cui@print(i.toStr())
			if(cnt < n - 1)
				do cui@print(",")
			else
				do cui@print("\n")
			end if
			do cnt :: cnt + 1
		end if
		do i :: i + 1
	end while
end func
0
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
0
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?