-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA. Diverse Permutation.cs
55 lines (45 loc) · 1.24 KB
/
A. Diverse Permutation.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace ConsoleApplication25
{
class Program
{
static void Main(string[] args)
{
var n = int.Parse(Console.ReadLine());
var init = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
for (int i = 0; i < n;i++)
{
if (isPrime(init[i]))
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
Console.ReadLine();
}
private static bool isPrime(long num)
{
long boundary = (long)Math.Ceiling(Math.Sqrt(num));
Console.WriteLine(boundary);
if (num == 1) return false;
if (num == 2) return true;
var ans = 0;
for (int i = 1; i <= boundary; i++)
{
if (num % i == 0)
{
ans++;
if (ans > 2)
return false;
}
}
if (ans == 1)
return false;
return true;
}
}
}