-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem007.cs
55 lines (49 loc) · 1.04 KB
/
Problem007.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace ProjectEuler.Solutions
{
using System.Collections.Generic;
using NUnit.Framework;
using ProjectEuler.Helper;
/// <summary>
/// 10001st prime.
/// By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
/// <para>What is the 10 001st prime number?</para>
/// </summary>
public class Problem007 : Problem
{
public override long Solution()
{
long result = 0;
int counter = 0;
foreach(long primeNumber in Primes.GetPrimeNumber())
{
counter++;
if(counter == 10001)
{
result = primeNumber;
break;
}
}
return result;
}
[Test]
public void TestForExample()
{
byte[] expectedPrimes = new byte[] { 2, 3, 5, 7, 11, 13 };
List<long> primes = new List<long>();
foreach (long prime in Primes.GetPrimeNumber())
{
primes.Add(prime);
if(primes.Count == 6)
{
break;
}
}
Assert.AreEqual(expectedPrimes, primes);
}
[Test]
public void TestForProblem()
{
Assert.AreEqual(104743, this.Solution());
}
}
}