链接到问题:Ugly Numbers
您如何找到针对丑数的强力(简单方法方法)解决方案的大O。
我看到这部分代码:
/* Function to check if a number is ugly or not */
int isUgly(int no)
{
no = maxDivide(no, 2);
no = maxDivide(no, 3);
no = maxDivide(no, 5);
return (no == 1)? 1 : 0;
}
每个步骤需要log_2(x) + log_3(x) + log_5(x)
个步骤,其中x = no
因此,这意味着运行时为(log_2(x)+ log_3(x)+ log_5(x))n,其中x是输出结果。但是,算法的结果不能成为Big O表示法的一部分吗?如果不能,则将其减少为c n对吗?其中c>结果。正确的证明方法是什么?
isUgly