欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1646C.Factorials and Powers of Two
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, ). For example , , and are powerful numbers, because , , and but , , or 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 .
Note
In the first test case, can be represented as , where and are powerful numbers. Because 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 as the sum of three powerful numbers is . We can show that there is no way to represent as the sum of two or less powerful numbers.
In the third test case, 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 is a powerful number and the minimum in this case is .
Samples
4
7
11
240
17179869184
2
3
4
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |