python代码RE了,写了一份同样的C++的代码A了.求大佬帮忙分析一下python代码哪里有问题
a = eval(input())
n = eval(input())
tot = eval(input())
x = eval(input())
def fib(x):
if x == 1:
return 1
if x == 2:
return 1
return fib(x - 1) + fib(x - 2)
def findb(x):
if x <= 3:
return 0
ans = 0
for i in range(1, x - 2):
ans += fib(i)
return ans
def finda(x):
if x <= 4:
return 2
ans = 2
for i in range(1, x - 3):
ans += fib(i)
return ans
b = (tot - finda(n - 1) * a) / findb(n - 1)
print(finda(x) * a + findb(x) * b)
#include <cstdio>
using namespace std;
int a, b, n, x, tot;
int fib(int x) {
if(x == 1 or x == 2)
return 1;
return fib(x - 1) + fib(x - 2);
}
int finda(int x) {
if(x <= 4)
return 2;
int ans = 2;
for(int i = 1; i <= x - 4; i++)
ans += fib(i);
return ans;
}
int findb(int x) {
if(x <= 3)
return 0;
int ans = 0;
for(int i = 1; i <= x - 3; i++)
ans += fib(i);
return ans;
}
int main() {
scanf("%d%d%d%d", &a, &n, &tot, &x);
b = (tot - finda(n - 1) * a) / findb(n -1);
printf("%d", finda(x) * a + findb(x) * b);
return 0;
}