首页 > 试题广场 >

寻找丑数

[编程题]寻找丑数
  • 热度指数:4893 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。

输入描述:
整数N


输出描述:
第N个丑数
示例1

输入

6

输出

6
头像 把offer请过来
发表于 2022-04-21 16:11:00
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc 展开全文
头像 苦瓜!
发表于 2022-02-18 17:59:21
public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ i 展开全文
头像 gggone
发表于 2020-08-25 10:47:18
时间复杂度应该是O(n),但是多出了很多不必要的计算,不过空间复杂度只有O(1)。 n = int(input().strip()) count = 1 num = 1 num_copy = 1 while count < n: num_copy += 1 num = num_ 展开全文