找到第n个丑陋数字的算法 [英] algorithm to find nth ugly number

查看:72
本文介绍了找到第n个丑陋数字的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我最好的算法来找到第n个丑陋的数字。

Can any one give me best algorithm to find nth ugly number.

推荐答案

丑陋的数字是唯一的素数因子是2,3或5的数字。


1,2,3,4,5,6,8,9,10,12,15,......


显示前11个丑陋的数字。按照惯例,包含1个。


第4个最大的数字是4,7个是8,依此类推。
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence

1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...

shows the first 11 ugly numbers. By convention, 1 is included.

the 4th ugliest number is 4, 7th is 8 and so on.



[font = Times New Roman]丑陋的数字是唯一的素因子为2,3或5的数字。序列[/ font]


[font = Times新罗马] 1,2,3,4,5,6,8,9,10,12,15,... [/ font]


[font = Times New Roman ]显示前11个难看的数字。按照惯例,包括1。 [/ font]


第4个最大的数字是4,7个是8,依此类推。
[font=Times New Roman]Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence [/font]

[font=Times New Roman]1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... [/font]

[font=Times New Roman]shows the first 11 ugly numbers. By convention, 1 is included. [/font]

the 4th ugliest number is 4, 7th is 8 and so on.



首先,这里使用的标签不是一整套HTML标签,因此字体不起作用。


其次,我们不是为你做功课。如果您需要帮助,建议使用您的算法,或者如果您遇到问题,请将相关代码与您遇到的问题一起发布。有关详细信息,请参阅发布指南以获取更多信息。



Adrian

First, the tags used here are not a full set of the HTML tags, so font will not work.

Second, we are not here to do your homework for you. If you want help, suggest your algorithm or if you have code you are having problems with, post the relevant code along with the problem you are having. For more information see Posting Guidelines for more information.


Adrian



其次,我们不在这里为您做功课。如果您需要帮助,建议使用您的算法,或者如果您遇到问题,请将相关代码与您遇到的问题一起发布。有关详细信息,请参阅发布指南以获取更多信息。



Adrian
Second, we are not here to do your homework for you. If you want help, suggest your algorithm or if you have code you are having problems with, post the relevant code along with the problem you are having. For more information see Posting Guidelines for more information.


Adrian



这不是一个家庭工作问题,我太老了,不能做作业。 :)


我只是在阅读有关一些问题并试图找出最佳解决方案。


我为此迭代找到的算法找到从1到n的所有丑陋数字。因此有更高的复杂性。

是否有任何算法可以找到第n个丑陋的数字而没有找到第n个丑陋的数字而没有找到(n-1)这个丑陋的数字。

Its not a home work question, i am too old to do homework. :)

I am just reading about some problems and trying to come out with the best solution.

The algorithm i found for this iteratively finds all the n ugly numbers from 1 to n. Hence have higher complexity.
Is there any algorithm which could find nth ugly number without finding the nth ugly number without finding (n-1)th ugly number.


这篇关于找到第n个丑陋数字的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆