E - Good Numbers (hard version) (CodeForces - 1249C2)

给定一个正整数n,找到最小的好数m(n≤m),好数定义为可以表示为不同3的幂次之和的数。对于每个查询,判断n是否为好数,若不是,则找到大于n的最近的好数。解决方案包括创建一个数组存储3的幂,然后从最大幂开始减去,处理减的过程。
摘要由CSDN通过智能技术生成

The only difference between easy and hard versions is the maximum value of nn.

You are given a positive integer number nn. You really love good numbers so you want to find the smallest good number greater than or equal to nn.

The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).

For example:

  • 30 is a good number: 30=3^3+3^1,
  • 1 is a good number: 1=3^0,
  • 12 is a good number: 12=3^2+3^1,
  • but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2=3^0+3^0),
  • 19 is not a good number: you can't represent it as a sum of distinct powers of 3(for example, the representations 19=3^2+3^2+3^0=3^2+3^1+3^1+3^1+3^0 are invalid),
  • 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for exa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值