恶心的大数运算,,,
比赛的时候,如果没有模版,一般置后的题目了,,,,
题意:
要求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,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,sizeof(ans)); memset(last,sizeof(last)); last[0] = 1; last_l = ans_l = 1; for(int i = 1; i <= n; ++i) { add(); print(); product(); } return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。