大数,斐波那契
VIRUS OUTBREAK
https://ac.nowcoder.com/acm/problem/54573
题目连接 https://ac.nowcoder.com/acm/problem/54573
a = []
a.append(1)
a.append(1)
for i in range(2, 500):
a.append(a[i-1] + a[i-2])
while True:
n = int(input())
if n == -1: break
print("Hour: %d: %d cow(s) affected" % (n, a[n-1]))
include<bits/stdc++.h>
using namespace std;
int main()
{
int a[500][500]={0},z,i,j,jw=0;
//memset(a,0,sizeof(a));
a[1][499]=1;
a[2][499]=1;
for(i=3;i<500;i++){
for(j=499;j>=0;j--){
//if(a[i-1][j]+a[i-2][j]+jw==0)break;
a[i][j]=(a[i-1][j]+a[i-2][j]+jw)%10;
jw=(a[i-1][j]+a[i-2][j]+jw)/10;
}
}
while(1){
scanf("%d",&z);
if(z==-1)break;
printf("Hour: %d: ",z);
for(i=0;i<500;i++){
if(a[z][i]!=0)break;
}
for(j=i;j<500;j++)cout<<a[z][j];
printf(" cow(s) affected\n");
}
return 0;
}