# twim primes printer

logical prime
integer test,count,test2
define LUNOUT 	5
define YES	.true.
define NO	.false.

write (LUNOUT,1)
1	format(' list of first 10 twin primes '//)

count = 0
for (test=3;count <= 10;test=test+2)
  if (prime(test) & prime(test+2)) {
		test2 = test + 2
		write (LUNOUT,10) test,test2
		10 format(5x,2i7)
		count = count + 1
		}
call exit
end


# return YES iff n is a prime number
logical function prime(n)
integer n,factor

if (n==2)
	return (YES)
else if(n<=1 !! mod(n,2) == 0)
	return (NO)
else {
	for (factor=3;factor*factor<=n;factor = factor + 2)
		if (mod(n,factor) == 0)
			return (NO)

	return (YES)
     }
end
