2020-05-22 — 习题训练二-A
A - Candies
题意:给定n,输出满足x+2x+4x+⋯+2^k−1x=n的x的值 (k>1)
解题思路:2^k-1累加,判断其值是否被n整除即可
ac代码:
#include<iostream>
using namespace std;
int main(){
int t,n,i,s,sum;
cin>>t;
while(t--){
cin>>n;
s=1;
sum=1;
for(i=1;;i++){
s*=2;
sum+=s;
if(n%sum==0){
cout<<n/sum<<endl;
break;
}
}
}
return 0;
}