POJ3982:序列

來源:互聯網
上載者:User

Description

數列A滿足An = An-1 + An-2 + An-3, n >= 3

編寫程式,給定A0, A1 和 A2, 計算A99

Input

輸入包含多行資料

每行資料包含3個整數A0, A1, A2 (0 <= A0, A1, A2 <= 32767)
資料以EOF結束

Output

對於輸入的每一行輸出A99的值

Sample Input

1 1 1

Sample Output

69087442470169316923566147
 
#include <stdio.h>#include <string.h>#include <stdlib.h>void add(char a[],char b[],char back[]){    int i,j,k,up,x,y,z,l;    char *c;    if(strlen(a) > strlen(b))        l = strlen(a)+2;    else        l = strlen(b)+2;    c = (char*)malloc(l*sizeof(char));    i = strlen(a)-1;    j = strlen(b)-1;    k = 0;    up = 0;    while(j>=0 || i>=0)    {        if(i<0) x = '0';        else            x = a[i];        if(j<0) y = '0';        else            y = b[j];        z = x-'0'+y-'0';        if(up)            z++;        if(z>9)        {            up = 1;            z%=10;        }        else            up = 0;        c[k++] = z+'0';        i--;        j--;    }    if(up)        c[k++] = '1';    i = 0;    c[k] = '\0';    for(k-=1; k>=0; k--)        back[i++] = c[k];    back[i] = '\0';}int main(){    char a[1000],b[1000],c[1000],sum[1000];    int m,i;    while(~scanf("%s%s%s",a,b,c))    {        add(a,b,sum);        add(c,sum,sum);        int n = 5;        for(i = 1; i<=24; i++)        {            add(b,c,a);            add(sum,a,a);            add(c,sum,b);            add(b,a,b);            add(sum,a,c);            add(b,c,c);            add(a,b,sum);            add(c,sum,sum);        }        printf("%s\n",sum);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.