- static long GetNPrime(int count)//返回第count个素数
- {
- List<long> list = new List<long>();//顺序存放素数
- long startNumber = 1;
- while (list.Count < count)
- {
- if (IsPrime(startNumber, list)) list.Add(startNumber);
- startNumber++;
- }
- return --startNumber;
- }
-
- static bool IsPrime(long number, List<long> list)//判断number是否为素数
- {
- if (number == 1) return false;
- long max = (long)Math.Sqrt(number);
- foreach (long n in list)
- {
- if (number % n == 0) return false;
- if (n > max) break;
- }
- return true;
- }
posted @
2012-12-28 21:21
栗子·无限意志
阅读(
598)
评论()
编辑
收藏
举报