UVA -580 组合数学

时间:2023-11-25 23:45:32
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
ll f[];
ll g[];
ll qpow(ll a,ll b){
ll ans=;
while(b){
if (b&==)ans=ans*a;
a*=a;
b/=;
}
return ans;
}
void init(){
f[]=f[]=f[]=;
g[]=;g[]=;g[]=;
for (int i=;i<=;i++){
ll sum=;
for(int j=;j<=i-;j++){
sum=sum+g[j-]*qpow(,i-j-);
}
f[i]=qpow(,i-)+sum;
g[i]=qpow(,i)-f[i];
}
}
int main(){
init();
int n;
while(~scanf("%d",&n)&&n){
printf("%lld\n",f[n]);
}
return ;
}