在这道题中,你需要编写一个程序来输出0到n之间的所有丑数。
丑数是指只包含因子2、3、5的数字,例如6、8,但14不是丑数,因为它包含因子7。一般习惯上将1视为第一个丑数。
你可以使用以下思路来解决这道题:
定义一个数组,用来存储找到的丑数。
在循环中遍历数字0到n,对每个数字进行判断,看看它是否是丑数。
对于每个数字,如果它只包含因子2、3、5,那么就把它添加到丑数数组中。
最后,遍历丑数数组,输出所有丑数。
示例代码如下:
``` #include <stdio.h> #include <stdlib.h>
#define not ! #define and && #define or ||
#define ri register int #define rep(inc, frm, to) for (ri inc = frm; inc < (to); ++inc) #define rep2(inc, frm, to) for (ri inc = frm; inc > (to); --inc)
#define setbit(x, y) x |= 1 << y #define clrbit(x, y) x &= ~(1 << y) #define getbit(x, y) x >> y & 1 #define flipbit(x, y) x ^= 1 << y #define show_bin(x) { rep2(i, 31, ~0) printf("%d%c", getbit(x, i), i ? 0 : 10); }
#define swap(a, b) a ^= b, b ^= a, a ^= b #define r(x) x = read()
typedef long long int ll; #define rl(x) x = readll()
#define rch(x) x = readchar() #define rstr(x) x = readstr()
ll readll() { ll a = 0, b = 1; char ch = getchar(); while ((ch < '0' or ch > '9