Codeforces Round #774 (Div. 2)
比赛链接
Codeforces Round #774 (Div. 2)
C. Factorials and Powers of Two
A number is called powerful if it is a power of two or a factorial. In other words, the number is powerful if there exists a non-negative integer such that or , where (in particular, 0 ! ). For example 1,4 , and 6 are powerful numbers, because , and but 7,10 , or 18 are not.
You are given a positive integer . Find the minimum number such that can be represented as the sum of distinct powerful numbers, or say that there is no such .
Input
Each test contains multiple test cases. The first line contains the number of test cases . Description of the test cases follows.
A test case consists of only one line, containing one integer
Output
For each test case print the answer on a separate line.
If can not be represented as the sum of distinct powerful numbers, print .
Otherwise, print a single positive integer - the minimum possible value of .
Example
input
output
Note
In the first test case, 7 can be represented as , where 1 and 6 are powerful numbers. Because 7 is not a powerful number, we know that the minimum possible value of in this case is .
In the second test case, a possible way to represent 11 as the sum of three powerful numbers is . We can show that there is no way to represent 11 as the sum of two or less powerful numbers.
In the third test case, 240 can be represented as . Observe that is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, , so 17179869184 is a powerful number and the minimum in this case is .
解题思路
思维,dfs
可以发现不可能出现无解的情况(由二进制表示,一个数总是可以表示为若干个不相同的二次幂相加的形式),可以将所有小于等于 的乘方表示出来,共有 个数,然后每次暴力每次选择某一个乘方数或不选,最后再用若干个二次幂来表示剩余的数,注意当乘方数中包含 或 时,剩余的数的二次幂不能出现 或 ,否则两个数会重复
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/16048290.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!