Codeforces Round #636 A. Candies(水)
Recently Vova found nn candy wrappers. He remembers that he bought xx candies during the first day, 2x2x candies during the second day, 4x4x candies during the third day, …… , 2k−1x2k−1x candies during the kk -th day. But there is an issue: Vova remembers neither xx nor kk but he is sure that xx and kk are positive integers and k>1k>1 .
Vova will be satisfied if you tell him any positive integer xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n . It is guaranteed that at least one solution exists. Note that k>1k>1 .
You have to answer tt independent test cases.
The first line of the input contains one integer tt (1≤t≤1041≤t≤104 ) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (3≤n≤1093≤n≤109 ) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer xx and integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n .
Print one integer — any positive integer value of xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n .
7 3 6 7 21 28 999999999 999999984
1 2 1 7 4 333333333 333333328
高中题。。
#include <bits/stdc++.h> using namespace std; int fpow(int a,int b) { int ans=1; for(;b;b>>=1) { if(b&1)ans*=a; a*=a; } return ans; } int main() { int t; cin>>t; while(t--) { int n,k,i; cin>>n; for(k=2;;k++) { if(n%(fpow(2,k)-1)==0) { cout<<n/(fpow(2,k)-1)<<endl; break; } } } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!