Potřebuju napsat funkci, která bere jako argument číslo n a return (jako řetězec) nejnižší dostupné číslo, které lze vydělit všemi čísly od 1 do n. například, pokud n=4, pak funkce vrátí 12 jako 12/4 12/3 12/2 12/1 jsou celá čísla.
napsal jsem funkci, která funguje, když čísla jsou méně než 19.. nad 19 výpočetní čas je stále mnohem déle. může někdo mi dát tip, jak lépe mechanismus pro tuto funkci dělat to rychlejší
public static string Smallest(int n)
{
int good = 0;//will hold number of times we got divide with no remianders
int num = n;//smallest possible number is n
while (true)
{
good = 0;
for (int i=n; i>=1; i--)
{
if (num % i ==0) good++;//meaning we got zero remainder for the divide
if (good == n) return num.ToString();//num of times we got zero remainders == n.
}
num++;
}
}