恶心的大数运算,,,
比赛的时候,如果没有模版,一般置后的题目了,,,,
题意:
要求a,b,c,.....使得1-1/a-1/b-1/c-1/d.......的结果最小。。。
代码如下:
#include <cstdio>
#include <cstring>
#define MOD 100000000
long long ans[100000], last[100000], temp[100000];
int ans_l, last_l;
void add()
{
for(int i = 0; i < last_l; ++i)
ans[i] = last[i];
ans_l = last_l;
ans[0]+=1;
for(int i = 0; i < ans_l; ++i)
{
ans[i+1] += ans[i]/MOD;
ans[i] %= MOD;
}
while(ans[ans_l]!=0)
{
ans[ans_l+1] += ans[ans_l]/MOD;
ans[ans_l] %= MOD;
ans_l += 1;
}
}
void product()
{
int temp_l = last_l+ans_l-1;
memset(temp,0,sizeof(temp));
for(int i = 0; i < last_l; ++i)
for(int j = 0; j < ans_l; ++j)
temp[j+i]+=last[i]*ans[j];
for(int i = 0; i < temp_l; ++i)
{
temp[i+1] += temp[i]/MOD;
temp[i]%=MOD;
}
while(temp[temp_l]!=0)
{
temp[temp_l+1] += temp[temp_l]/MOD;
temp[temp_l] %= MOD;
temp_l += 1;
}
for(int i = 0; i < temp_l; ++i)
last[i] = temp[i];
last_l = temp_l;
}
void print()
{
for(int i = ans_l-1; i >= 0; i--)
i==ans_l-1?printf("%I64d", ans[i]):printf("%08I64d", ans[i]);
printf("\n");
}
int main ()
{
int n;
scanf("%d",&n);
memset(ans,0,sizeof(ans));
memset(last,0,sizeof(last));
last[0] = 1;
last_l = ans_l = 1;
for(int i = 1; i <= n; ++i)
{
add();
print();
product();
}
return 0;
}