题目链接
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
#define LL long long
#define INF 2000000000
LL p[];
int main()
{
int i;
LL a,fa,fb,b,n;
LL str,mid,end;
cin>>a>>fa>>b>>fb>>n;
if(a > b)
{
swap(a,b);
swap(fa,fb);
}
str = -INF;
end = INF;
while(str <= end)
{
mid = (str+end)/;
int f1,f2;
f1 = f2 = ;
memset(p,-,sizeof(p));
p[a+] = fa;
p[a++] = mid;
for(i = a+;i <= b;i ++)
{
p[i+] = p[i-+] + p[i-+];
if(p[i+] > INF)
{
f1 = ;
break;
}
if(p[i+] < -INF)
{
f2 = ;
break;
}
}
if(f1)
end = mid - ;
else if(f2)
str = mid + ;
else if(p[b+] == fb)
break;
else if(p[b+] > fb)
end = mid - ;
else if(p[b+] < fb)
str = mid + ;
}
if(n <= b&&n >= a)
;
else if(n < a)
{
p[a+] = fa;
p[a++] = mid;
for(i = a-;i >= n;i --)
{
p[i+] = p[i++] + p[i++];
}
}
else
{
p[a+] = fa;
p[a++] = mid;
for(i = a+;i <= n;i ++)
{
p[i+] = p[i-+] + p[i-+];
}
}
cout<<p[n+]<<endl;
return ;
}