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)

static bool isPrime(int n) {
  if ((n > 2 && (n & 1) == 0) // check is it even
     || n <= 1  //check for -ve
     || (n > 3 && (n % 3 ==  0)))  // check for 3 divisable
    false;

  int maxLookup = (int) Math.sqrt(n);
  for (int i = 3; (i+2) <= maxLookup; i = i + 6)
    if (n % (i+2) == 0 || n % (i+4) == 0) false;
  true;
}

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: 439 / 449
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)