Jump to content

Primes


Gargamel

Recommended Posts

Welcome to the forum !

And ... nope on first sight 2615 is divisable by 5 (and maybe others). Want to try again ?

Spoiler

Edit: a quick&dirty and terribly ineffective C function to check if n is prime:


static inline int isPrime( int n ) {
	if( 0 == ( n % 2 ) )
		return 0;
	if( 0 == ( n % 3 ) )
		return 0;
	if( 0 == ( n % 5 ) )
		return 0;
	int l = n/2;
	for( int c = 7; c <= l; c += 2 ) {
		if( 0 == ( n % c ) ) {
			// printf( "%d is divisable by %d\n", n, c );
			return 0;
		}
	}
	return 1;
}

 

 

Edited by Green Baron
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...