-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010.cs
More file actions
59 lines (49 loc) · 1.14 KB
/
Copy path010.cs
File metadata and controls
59 lines (49 loc) · 1.14 KB
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
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Summation of primes
//Problem 10
//The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
//Find the sum of all the primes below two million.
namespace _010
{
class Program
{
static void Main(string[] args)
{
double number = 0;
double x = 2;
while (x < 2000000)
{
if (isPrime(x))
{
number += x;
}
x++;
}
Console.WriteLine(number);
}
static bool isPrime(double number)
{
if (number % 2 == 0)
{
if (number == 2)
{
return true;
}
return false;
}
double max = (double)Math.Sqrt(number);
for (int i = 3; i <= max; i += 2)
{
if ((number % i) == 0)
{
return false;
}
}
return true;
}
}
}