Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

11
LINES

< > BotCompany Repo | #1010223 // isPrime - check if a number is prime

JavaX fragment (include)

1  
static bool isPrime(int n) {
2  
  if ((n > 2 && (n & 1) == 0) // check is it even
3  
     || n <= 1  //check for -ve
4  
     || (n > 3 && (n % 3 ==  0)))  // check for 3 divisable
5  
    false;
6  
7  
  int maxLookup = (int) Math.sqrt(n);
8  
  for (int i = 3; (i+2) <= maxLookup; i = i + 6)
9  
    if (n % (i+2) == 0 || n % (i+4) == 0) false;
10  
  true;
11  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010223
Snippet name: isPrime - check if a number is prime
Eternal ID of this version: #1010223/3
Text MD5: 5335f90ad1a9118ebb19f92bda6891e4
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-06 21:20:54
Source code size: 338 bytes / 11 lines
Pitched / IR pitched: No / No
Views / Downloads: 373 / 385
Version history: 2 change(s)
Referenced in: [show references]