Editorial for Lát gạch
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của flashmt
const base=1000000000; dg=9; type bignum=array[0..5] of longint; var n,i,t:longint; f:array[1..100] of bignum; procedure plus(var a,b,c:bignum); var i,mem:longint; begin a[0]:=b[0]; mem:=0; for i:=1 to a[0] do begin a[i]:=b[i]+c[i]+mem; if a[i]>=base then begin a[i]:=a[i]-base; mem:=1 end else mem:=0; end; if mem=1 then begin inc(a[0]); a[a[0]]:=mem; end; end; procedure wf(a:bignum); var i,j,l:longint; s:string; begin for i:=a[0] downto 1 do begin if i<a[0] then begin str(a[i],s); l:=length(s); for j:=l+1 to dg do write(0); end; write(a[i]); end; writeln; end; begin f[1,0]:=1; f[1,1]:=1; f[2,0]:=1; f[2,1]:=2; for i:=3 to 100 do plus(f[i],f[i-1],f[i-2]); read(t); for i:=1 to t do begin read(n); wf(f[n]); end; end.
Code mẫu của happyboy99x
#include <cstdio> #include <algorithm> using namespace std; #define L_MAX 1000 //length max #define RADIX 1000000000 #define N_MAX 100 + 2 #define REP(i, n) for( int i = 0, _n = (n); i < _n ; ++i ) #define REPD(i, n) for( int i = (n)-1; i >= 0; --i ) #define FOR(i, a, b) for( int i = (a), _b = (b); i <= _b; ++i ) int f[N_MAX][L_MAX]; int l[N_MAX]; int countNum; //----------------------------PROTOTYPE------------------------------- void init(); void calc(int, int); void plus(int *, int *, int *, int, int, int & ); void print( int *, int l ); //-------------------------------------------------------------------- void init() { f[0][0] = 0; l[0] = 1; f[1][0] = 1; l[1] = 1; countNum = 2; } void calc( int a, int b ) { countNum = b + 1; FOR(i, a, b) plus( f[i-1], f[i-2], f[i], l[i-1], l[i-2], l[i] ); } void print( int a[], int l ) { printf( "%d", a[l-1] ); REPD(i, l-1) printf( "%09d", a[i] ); } void plus( int a[], int b[], int c[], int la, int lb, int &lc ) { int carry = 0; lc = max(la, lb); REP(i, lc) { c[i] = a[i] + b[i] + carry; if ( c[i] >= RADIX ) { carry = 1; c[i] -= RADIX; } else carry = 0; } if (carry) c[lc++] = 1; } int main() { init(); int tc, n; scanf("%d",&tc); while ( tc-- && scanf( "%d", &n) == 1 ) { if ( n+1 >= countNum ) calc( countNum, n+1 ); print( f[n+1], l[n+1] ); printf( "\n" ); } return 0; }
Code mẫu của ladpro98
program latgach; uses math; type bignum=string[30]; const fi=''; var n,t,i:longint; f:array[1..100] of string[30]; inp:text; function cong(a,b:bignum):bignum; var c:bignum; x,y,sum,i,carry:longint; begin c:='';carry:=0; while length(a)<length(b) do a:='0'+a; while length(b)<length(a) do b:='0'+b; for i:=length(a) downto 1 do begin x:=ord(a[i])-48; y:=ord(b[i])-48; sum:=x+y+carry; carry:=sum div 10; c:=chr(sum mod 10 + 48) + c; end; if carry>0 then c:='1'+c; exit(c); end; begin assign(inp,fi); reset(inp); readln(inp,t); f[1]:='1'; f[2]:='2'; for i:=3 to 100 do f[i]:=cong(f[i-1],f[i-2]); for i:=1 to t do begin readln(inp,n); writeln(f[n]); end; close(inp); end.
Code mẫu của hieult
#include<stdio.h> #include<string.h> main() { int x,a[100],i,b[23],c[23],m; scanf("%d",&x); for(int j=0;j<x;j++) scanf("%d",&a[j]); for(int j=0;j<x;j++) { for(int k=0;k<=21;k++) { b[k]=0;c[k]=0; } b[22]=0; c[22]=1; i=0; while(1) { for(int t=22;t>=0;t--) { m=b[t]; b[t]=(b[t]+c[t])%10; if(b[t]<c[t]||m==10) b[t-1]++; } i++; if(i==a[j]) { int u=0; for(int t=0;t<=22;t++) { u+=b[t]; if(u==0) continue; printf("%d",b[t]%10); } printf("\n"); break; } for(int t=22;t>=0;t--) { m=c[t]; c[t]=(b[t]+c[t])%10; if(c[t]<b[t]||m==10) c[t-1]++; } i++; if(i==a[j]) { int u=0; for(int t=0;t<=22;t++) { u+=c[t]; if(u==0) continue; printf("%d",c[t]%10); } printf("\n"); break; } } } }
Code mẫu của ll931110
Program LATGACH; Const Input = ''; Output = ''; Var d,test: array[1..100] of byte; F: array[1..100,1..30] of byte; i,n: integer; Procedure enter; Var fi: text; i: integer; Begin Assign(fi, input); Reset(fi); Readln(fi, n); For i:= 1 to n do readln(fi, test[i]); Close(fi); Fillchar(F, sizeof(F), 0); End; Procedure calc; Var i,j: integer; Begin F[1,1]:= 1; d[1]:= 1; F[2,1]:= 2; d[2]:= 1; For i:= 3 to 100 do Begin For j:= 1 to d[i - 1] do Begin F[i,j]:= F[i,j] + F[i - 1,j] + F[i - 2,j]; If F[i,j] > 9 then Begin F[i,j + 1]:= 1; F[i,j]:= F[i,j] - 10; End; End; d[i]:= d[i - 1]; If F[i, d[i - 1] + 1] <> 0 then inc(d[i]); End; End; Procedure printresult; Var fo: text; i,j: integer; Begin Assign(fo, output); Rewrite(fo); For i:= 1 to n do Begin For j:= d[test[i]] downto 1 do write(fo, F[test[i],j]); Writeln(fo); End; Close(fo); End; Begin enter; calc; printresult; End.
Code mẫu của skyvn97
program latgach; uses crt; type bignum=string; const max=111; var opt:array[1..max] of bignum; t,c,n:integer; a,b:bignum; function bigplus(a,b:bignum):bignum; var i,carry,s:integer; result:bignum; begin result:=''; while length(a)<length(b) do a:='0'+a; while length(b)<length(a) do b:='0'+b; carry:=0; for i:=length(a) downto 1 do begin s:=ord(a[i])+ord(b[i])+carry-96; carry:=s div 10; result:=chr(s mod 10+48)+result; end; if carry=1 then result:='1'+result; bigplus:=result; end; procedure init; var i:integer; begin opt[1]:='1'; opt[2]:='2'; for i:=3 to max do opt[i]:=bigplus(opt[i-1],opt[i-2]); end; begin init; readln(t); for c:=1 to t do begin readln(n); writeln(opt[n]); end; end.
Code mẫu của khuc_tuan
import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { BigInteger[] f = new BigInteger[101]; f[0] = BigInteger.ONE; f[1] = BigInteger.ONE; for(int i=2;i<101;++i) f[i] = f[i-1].add(f[i-2]); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;++i) System.out.println(f[sc.nextInt()]); } }
Comments