-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (39 loc) · 885 Bytes
/
Program.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
using System;
namespace test
{
class Test{
public static void Main()
{
int number = int.Parse(Console.ReadLine());
if (number <= 2)
{
Console.WriteLine(2);
}
else
{
Console.Write(NextPrime(number));
}
}
static int NextPrime(int n)
{
if (IsPrime(n))
{
return n;
}
return NextPrime(n + 1);
}
static bool IsPrime(int n)
{
for (int i = 2; i * i <= n; i++)
{
if (IsDivisor(n, i)) return false;
}
return true;
}
static bool IsDivisor(int n, int d)
{
if (n % d == 0) return true;
return false;
}
}
}