Factorial Primes

Factorial primes with gawk

#! /usr/bin/gawk -f
function isprime(n, i) {
  if(n==2)return 1
  if(n<2||n%2==0)return 0
  for(i=3;i*i<=n;i+=2)
    if(n%i==0)return 0
  return 1
}
BEGIN {
  for(x=i=1;z<10;i++){
    x*=i
    if(isprime(x-1)){z++;print i"! - 1 = "x-1}
    if(isprime(x+1)){z++;print i"! + 1 = "x+1}
  }
}

The next output would be (if you had the patience to do it):

27! + 1 = 10,888,869,450,418,352,160,768,000,001

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment