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
E - Good Numbers (hard version) (CodeForces - 1249C2)
最新推荐文章于 2019-12-11 19:28:26 发布
给定一个正整数n,找到最小的好数m(n≤m),好数定义为可以表示为不同3的幂次之和的数。对于每个查询,判断n是否为好数,若不是,则找到大于n的最近的好数。解决方案包括创建一个数组存储3的幂,然后从最大幂开始减去,处理减的过程。
摘要由CSDN通过智能技术生成