1314A-Candies

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int pw = 2; pw < 30; ++pw) {
			int val = (1 << pw) - 1;
			if (n % val == 0) {
				cerr << val << endl;
				cout << n / val << endl;
				break;
			}
		}
	}
	
	return 0;
}

1概念编辑std::cerr是ISO C++标准错误输出流,对应于ISO C标准库的stderr。与std::cout不同,ISO C++要求当cerr被初始化后,cerr.flags() & unitbuf非零(保证流在每次输出操作后被刷新),且cerr.tie()返回&cout。 即cerr默认和cout同步但无缓冲。
2cerr与cout的区别编辑cout对应于标准输出流,默认情况下是显示器。这是一个被缓冲的输出,可以被重定向。cerr对应标准错误流,用于显示错误消息。默认情况下被关联到标准输出流,但它不被缓冲,也就说错误消息可以直接发送到显示器,而无需等到缓冲区或者新的换行符时,才被显示。一般情况下不被重定向。例如下面代码编译后生成test.exe// test.cpp#include
using namespace std;
int main()
{cout << “hello world—cout” << endl ;
cerr << “hello world—cerr” << endl ;
return 0;}
3为什么要用cerr编辑比如,你的程序遇到调用栈用完了的威胁(无限,没有出口的递归)。你说,你到什么地方借内存,存放你的 错误信息?所以有了cerr。其目的,就是在你最需要它的紧急情况下,还能得到输出功能的支持。 缓冲区的目的,就是减少刷屏的次数——比如,你的程序输出圣经中的一篇文章。不带缓冲的话,就会每写一个字母,就输出一个字母,然后刷屏。有了缓冲,你将看到若干句子“同时”就出现在了屏幕上(由内存翻新到显存,然后刷新屏幕)

题解的做法看不懂
附一个简单的

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn=1e6+7;
ll pre[maxn];
int main(){
int k;
cin>>k;
for(int i=1;i<=32;i++){
pre[i]=pre[i-1]+(1<<(i-1));
}
while(k–){
int n;
scanf("%d",&n);
for(int i=2;i<=32;i++){
if(n%pre[i]==0){
printf ("%d\n",n/pre[i]);
break;
}
}
}
}

最后是题目
test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently 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.InputThe 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.OutputPrint 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.ExampleinputCopy7
3
6
7
21
28
999999999
999999984
outputCopy1
2
1
7
4
333333333
333333328
NoteIn the first test case of the example, one of the possible answers is x=1,k=2x=1,k=2. Then 1⋅1+2⋅11⋅1+2⋅1 equals n=3n=3.In the second test case of the example, one of the possible answers is x=2,k=2x=2,k=2. Then 1⋅2+2⋅21⋅2+2⋅2 equals n=6n=6.In the third test case of the example, one of the possible answers is x=1,k=3x=1,k=3. Then 1⋅1+2⋅1+4⋅11⋅1+2⋅1+4⋅1 equals n=7n=7.In the fourth test case of the example, one of the possible answers is x=7,k=2x=7,k=2. Then 1⋅7+2⋅71⋅7+2⋅7 equals n=21n=21.In the fifth test case of the example, one of the possible answers is x=4,k=3x=4,k=3. Then 1⋅4+2⋅4+4⋅41⋅4+2⋅4+4⋅4 equals n=28n=28.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值