ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#159102 | #4. 爬楼梯 | alex_liu | 100 | 2ms | 1244kb | C++ | 717b | 2022-09-19 13:42:45 | 2022-09-19 13:42:46 |
answer
#include<bits/stdc++.h>
int n,ns=1;
int a[5010],b[5010],c[5010];
void Fibonacci(){
a[1]=1,b[1]=2;
for(int i=3;i<=n;i++){
for(int j=1;j<=ns;j++)c[j]=a[j]+b[j];
for(int j=1;j<=ns;j++){
if(c[j]>9){
c[j+1]+=c[j]/10;
c[j]%=10;
if(j+1>ns)ns++;
}
}
for(int j=1;j<=ns;j++)a[j]=b[j];
for(int j=1;j<=ns;j++)b[j]=c[j];
}
}
int main(){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
scanf("%d",&n);
if(n<3){
printf("%d",n);
return 0;
}
Fibonacci();
for(int i=ns;i>0;i--)printf("%d",b[i]);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
36
output:
24157817
result:
ok 1 number(s): "24157817"
Test #2:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
30
output:
1346269
result:
ok 1 number(s): "1346269"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
29
output:
832040
result:
ok 1 number(s): "832040"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
21
output:
17711
result:
ok 1 number(s): "17711"
Test #5:
score: 10
Accepted
time: 1ms
memory: 1244kb
input:
16
output:
1597
result:
ok 1 number(s): "1597"
Test #6:
score: 10
Accepted
time: 1ms
memory: 1240kb
input:
12
output:
233
result:
ok 1 number(s): "233"
Test #7:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
9
output:
55
result:
ok 1 number(s): "55"
Test #8:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #9:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
4
output:
5
result:
ok 1 number(s): "5"
Test #10:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
1
output:
1
result:
ok 1 number(s): "1"