-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxPrimeFactor.cs
More file actions
43 lines (42 loc) · 1.04 KB
/
MaxPrimeFactor.cs
File metadata and controls
43 lines (42 loc) · 1.04 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerrankSolution
{
public class MaxPrimeFactor
{
private static bool isPrime(long n)
{
long i;
for (i=2; i <= Math.Sqrt(n); i++)
{
if (n % i == 0) { return false; }
}
return i==n/2+1;
}
public static void Execute()
{
long.TryParse(Console.ReadLine(), out long n);
double factorsProduct = 1;
int maxFactor = 0;
for (long i = 2; i <= n; i++)
{
if (isPrime(i))
{
factorsProduct *= i;
if (factorsProduct <= n)
{
maxFactor++;
}
else
{
break;
}
}
}
Console.WriteLine(maxFactor);
}
}
}