递归题解(超简便)
2025-07-02 12:26:59
发布于:江苏
37阅读
0回复
0点赞
递归代码:
#include<iostream>
using namespace std;
int n;
void f(int n, int m){
if(n == 0) return;
f(n/2, m*2);
if(n%2 == 1) cout << m << ' ';
}
int main(){
cin >> n;
if(n%2 == 1) cout << -1;
else f(n, 1);
return 0;
}
这里空空如也
有帮助,赞一个