P2609 题解
FurippuWRY · · 题解
题意:有一数列
现有一数
看见
t = int(input())
while t > 0 :
a = 1
b = 0
n = int(input())
while n > 0 :
if (n % 2 == 0) : a += b
else : b += a
n //= 2
t -= 1
print(b)
此段代码的意思就相当于:
#include <bits/stdc++.h>
using namespace std;
int n, t;
int main() {
cin >> t;
while (t--) {
cin >> n;
int a = 1, b = 0;
while (n) {
if (n % 2 == 0) a += b;
else b += a;
n /= 2;
}
cout << b << '\n';
}
return 0;
}
当然,这坨 C++ 代码是过不了这题的,会爆,要想用 C++ 过这题就老老实实打高精罢。
警钟:用递归会超时。