我需要编写一个函数,需要作为一个参数的数目n和返回(string)的最低数量,可划分所有数从1到n. 例如,如果n=4的功能将返回12 12月4日12/3 12/2 12/1是整数。
我已经写了一个功能,其正常工作时数少于19..上面的19所述的计算时间变得更长的时间。 有人能给我一个暗示如何更好的机制,这一功能做的更快
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++;
}
}