Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #17638

Primality by Wilson Theorem

From janus <emekamicro@gmail.com>
Newsgroups comp.lang.c
Subject Primality by Wilson Theorem
Date 2012-02-19 23:54 -0800
Organization http://groups.google.com
Message-ID <21835173.5344.1329724442804.JavaMail.geo-discussion-forums@vbtb2> (permalink)

Show all headers | View raw


# include <stdio.h>


long long int  factorial( long long int num){
	long long int tempNum ;
	long long int acc = 1;
	for(tempNum = 1; tempNum < num + 1; ++tempNum){
		acc = acc * tempNum;
	}
	return acc;
	
}

 long long int  cosAndFactorial( long long int  num){
	long long int factValue = factorial(num - 1);
        long long int result = (factValue + (long long int)1 ) % num;
	return result;
	
}

int main (){
	long long  int i;
	int pcount = 0;
	long long int value;
	for( i =  3; i < 1000000; i = i + 2){

		value = cosAndFactorial(i);

		if((int)value == 0){
			++pcount;
			printf("Factorial : This number %llu is a Prime\n", i);
		}
		if(pcount == 10) {
			break;
		}
	}
	
return 0;
}	

I am trying to code Wilsons Theorem, http://mathworld.wolfram.com/WilsonsTheorem.html?affilliate=1
The above returns;
Factorial : This number 3 is a Prime
Factorial : This number 5 is a Prime
Factorial : This number 7 is a Prime
Factorial : This number 11 is a Prime
Factorial : This number 13 is a Prime
Factorial : This number 17 is a Prime
Factorial : This number 19 is a Prime
Factorial : This number 35 is a Prime


Regards, \Janus

Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Primality by Wilson Theorem janus <emekamicro@gmail.com> - 2012-02-19 23:54 -0800
  Re: Primality by Wilson Theorem Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-20 00:39 -0800
    Re: Primality by Wilson Theorem Noob <root@127.0.0.1> - 2012-02-20 11:50 +0100
  Re: Primality by Wilson Theorem "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-02-20 01:15 -0800
  Re: Primality by Wilson Theorem pacman@kosh.dhis.org (Alan Curry) - 2012-02-20 09:31 +0000
    Re: Primality by Wilson Theorem gwowen <gwowen@gmail.com> - 2012-02-20 03:44 -0800
  Re: Primality by Wilson Theorem Barry Schwarz <schwarzb@dqel.com> - 2012-02-20 10:33 -0800
    Re: Primality by Wilson Theorem janus <emekamicro@gmail.com> - 2012-02-20 11:12 -0800
      Re: Primality by Wilson Theorem Paul <nospam@needed.com> - 2012-02-20 16:21 -0500
        Re: Primality by Wilson Theorem janus <emekamicro@gmail.com> - 2012-02-21 03:08 -0800
    Re: Primality by Wilson Theorem Ike Naar <ike@iceland.freeshell.org> - 2012-02-20 22:52 +0000
      Re: Primality by Wilson Theorem Ike Naar <ike@iceland.freeshell.org> - 2012-02-20 22:55 +0000
  Re: Primality by Wilson Theorem Robert Miles <milesrf@Usenet-News.net> - 2012-03-31 00:38 -0500
    Re: Primality by Wilson Theorem 88888 Dihedral <dihedral88888@googlemail.com> - 2012-04-03 12:06 -0700

csiph-web