-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_Euler_5_Smallest_multiple.cs
More file actions
58 lines (53 loc) · 1.42 KB
/
Copy pathProject_Euler_5_Smallest_multiple.cs
File metadata and controls
58 lines (53 loc) · 1.42 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
internal class Program
{
private static void Main(string[] args)
{
int limit = 50;
Console.WriteLine("Reps");
int t = Convert.ToInt32(Console.ReadLine());
for (int a0 = 0; a0 < t; a0++)
{
Console.WriteLine("Number please");
int n = Convert.ToInt32(Console.ReadLine());
var primes= GetPrimes(n);
int smallestmultiple = 1;
foreach (var prime in primes)
{
int biggestPower = GetBiggestPowerOfN(prime, n);
smallestmultiple = (int)(smallestmultiple * Math.Pow(prime, biggestPower));
}
Console.WriteLine(smallestmultiple);
}
}
public static int GetBiggestPowerOfN(int n, int t)
{
int power = 1;
while (Math.Pow(n, power) <= t)
{
power ++;
}
int largestPower = power -1;
return largestPower;
}
public static List<int> GetPrimes(int limit)
{
List<int> primes = new List<int>();
for (int i = 2; i <= limit; i++)
{
bool isPrime = true;
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
primes.Add(i);
}
}
return primes;
}
}