c语言:项目2.寻找丑数。 我们把只包含因子2、3、5的数字成为丑数,例如6,8;但14就不是丑数,因为含有因子7。一般习惯上把1当成第一个丑数。 要求,输入一个数字n,试着编程输出0至n之间的所有丑...

在这道题中,你需要编写一个程序来输出0到n之间的所有丑数。

丑数是指只包含因子2、3、5的数字,例如6、8,但14不是丑数,因为它包含因子7。一般习惯上将1视为第一个丑数。

你可以使用以下思路来解决这道题:

  1. 定义一个数组,用来存储找到的丑数。

  2. 在循环中遍历数字0到n,对每个数字进行判断,看看它是否是丑数。

  3. 对于每个数字,如果它只包含因子2、3、5,那么就把它添加到丑数数组中。

  4. 最后,遍历丑数数组,输出所有丑数。

示例代码如下:

``` #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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值