2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Solution
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[]
args) {
int testCases =
Convert.ToInt32(Console.ReadLine());
int[] numbers = new
int[testCases];
for (int i = 0; i
< testCases; i++)
{
numbers[i] =
Convert.ToInt32(Console.ReadLine());
}
foreach (int number
in numbers)
{
long product =
1;
for (int i = 2;
i <= number; i++)
{
if(IsPrime(i))
{
int
temp = i;
for(int
j=2;j<=number;j++)
{
if(Math.Pow(Convert.ToDouble(i),Convert.ToDouble(j))>number)
{
break;
}
else
{
temp = Convert.ToInt32(Math.Pow(Convert.ToDouble(i),
Convert.ToDouble(j)));
}
}
product
= product * temp;
}
}
Console.WriteLine(product);
}
}
public static bool
IsPrime(int number)
{
if (number == 2 || number
== 3)
return true;
else
{
bool flag =
true;
for (int i = 2;
i <= Math.Sqrt(number); i++)
{
if (number
% i == 0)
{
flag =
false;
break;
}
}
return flag;
}
}
}
|