3 Array<int> primeList { [ 2 ], minAllocSize = 64 };
8 bool HasPrimeFactor(int x)
10 int max = (int)floor(sqrt((double)x));
15 if(x % i == 0) return true;
20 public int GetPrime(int x)
22 if(x > primeList.count - 1)
24 for (; primeList.count != x; index += 2)
25 if(!HasPrimeFactor(index))
27 if(primeList.count >= primeList.minAllocSize) primeList.minAllocSize *= 2;
31 return primeList[x-1];
35 class PrimeApp : Application
40 int num = argc > 1 ? atoi(argv[1]) : 1;
41 PrintLn(fp.GetPrime(num));