加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

URAL - 1108 Heritage(大数)

发布时间:2020-12-14 04:03:52 所属栏目:大数据 来源:网络整理
导读:恶心的大数运算,,, 比赛的时候,如果没有模版,一般置后的题目了,,,, 题意: 要求a,b,c,.....使得1-1/a-1/b-1/c-1/d.......的结果最

恶心的大数运算,,,

比赛的时候,如果没有模版,一般置后的题目了,,,,

题意:

要求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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读