Sha256: 1c7d7544eedc4bdaf0bf2628c36ff2892a57225bebe9190bc3125166d2fef0da
Contents?: true
Size: 529 Bytes
Versions: 132
Compression:
Stored size: 529 Bytes
Contents
#import "NthPrimeExample.h" @implementation NthPrime : NSObject +(int)primeNum:(int)primeNum { if (primeNum == 0) { return 0; } int currentPrime = 0; int i = 0; while (currentPrime <= primeNum) { i += 1; if ([self isPrime:i]){ currentPrime += 1; } } return i; } +(BOOL)isPrime:(int)n { if (n == 2 || n == 3) { return YES; } if (n % 2 == 0 || n % 3 == 0) { return NO; } int i = 5; int w = 2; while (i * i <= n) { if (n % i == 0) { return NO; } i += w; w = 6 - w; } return YES; } @end
Version data entries
132 entries across 132 versions & 1 rubygems