Musím napísať funkciu, ktorá berie ako argument číslo n a vrátiť (ako reťazec) najnižšie dostupné číslo, ktoré môže rozdeliť všetky čísla od 1 do n. napríklad, ak n=4, potom funkcia vráti 12 ako 12/4 12/3 12/2 12/1 sú celé čísla.
napísal som funkcia pre to, čo funguje v poriadku, keď sú čísla menej ako 19.. nad 19 výpočtovej čas je stále oveľa dlhšie. niekto môže mi dať tip, ako lepšie mechanizmus pre túto funkciu, ak chcete robiť to rýchlejšie
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++;
}
}