1 条题解
-
0
C :
#include<stdio.h> void main() { int a, n, m, x; scanf("%d%d%d%d",&a,&n,&m,&x); int f[24]; f[1] = 1; f[2] = 1; for(int i = 3; i < 24; i++) { f[i] = f[i-1] + f[i-2]; } printf("%d\n",(f[x-2]+1)*a+(f[x-1]-1)*(m-(f[n-3]+1)*a)/(f[n-2]-1)); }
C++ :
#include<stdio.h> int main() { int a,n,m,x,k,i,b[100],c[100],d[100]; while(scanf("%d%d%d%d",&a,&n,&m,&x)!=EOF) { if(n<=3) { printf("%d\n",a); continue; } if(x==n) { printf("0\n"); continue; } k=1; b[1]=a,b[2]=a; c[1]=a,d[1]=0; b[n-1]=0; while(b[n-1]!=m) { c[2]=k,d[2]=k; for(i=3;i<=n-1;i++) { c[i]=c[i-1]+c[i-2]; d[i]=c[i-1]; b[i]=b[i-1]+c[i]-d[i]; } k++; } printf("%d\n",b[x]); } return 0; }
Pascal :
var a,n,x,m,s,i:longint; a1:array[1..2,1..20] of longint; a2:array[1..2,1..20] of longint; a3:array[1..2,1..20] of int64; begin readln(a,n,m,x); a1[1,1]:=1;a1[1,2]:=0; a1[2,1]:=0;a1[2,2]:=1; a2[1,1]:=0;a2[1,2]:=0; a2[2,1]:=0;a2[2,2]:=1; a3[1,1]:=1;a3[1,2]:=1; for i:=3 to 20 do begin a1[1,i]:=a1[1,i-1]+a1[1,i-2]; a1[2,i]:=a1[2,i-1]+a1[2,i-2]; a2[1,i]:=a1[1,i-1]; a2[2,i]:=a1[2,i-1]; a3[1,i]:=a3[1,i-1]+a1[1,i]-a2[1,i]; a3[2,i]:=a3[2,i-1]+a1[2,i]-a2[2,i]; end; s:=(m-a3[1,n-1]*a) div a3[2,n-1]; writeln(a3[1,x]*a+a3[2,x]*s); end.
Python :
# coding=utf-8 #a,n,m,x=5,7,32,4 a,n,m,x=map(int,input().split()) ls1=[[1,0],[1,0],[2,0]] ls2=[[1,0],[0,1],[1,1]] for i in range(3,n): an2=ls2[i-1][0]+ls2[i-2][0] bn2=ls2[i-1][1]+ls2[i-2][1] ls2.append([an2,bn2]) an1=ls1[i-1][0]+ls2[i-2][0] bn1=ls1[i-1][1]+ls2[i-2][1] ls1.append([an1,bn1]) b=(m-ls1[n-2][0]*a)//ls1[n-2][1] print(ls1[x-1][0]*a+ls1[x-1][1]*b)
- 1
信息
- ID
- 190
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者