You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
//高精度+裴波那契数列
//本题目考点:
//1、递推
//2、递推关系式的推导: 找出任意一个位置, 思考它是怎么来的, 再用加法原理。
vector < int > add ( vector < int > & A , vector < int > & B ) {
if ( A . size ( ) < B . size ( ) ) return add ( B , A ) ;
vector < int > C ;
int t = 0 ;
for ( int i = 0 ; i < A . size ( ) ; i + + ) {
t + = A [ i ] ;
if ( i < B . size ( ) ) t + = B [ i ] ;
C . push_back ( t % 10 ) ;
t / = 10 ;
}
if ( t ) C . push_back ( t ) ;
return C ;
}
int main ( ) {
int m , n ;
cin > > m > > n ;
vector < int > A , B , C ;
A . push_back ( 1 ) ;
B . push_back ( 1 ) ;
for ( int i = 3 ; i < = n - m + 1 ; i + + ) {
C = add ( A , B ) ;
//对加数需要重新赋值
//A<---B
A . assign ( B . begin ( ) , B . end ( ) ) ;
//B<---C
B . assign ( C . begin ( ) , C . end ( ) ) ;
}
//倒序输出结果
for ( int i = B . size ( ) - 1 ; i > = 0 ; i - - ) printf ( " %d " , B [ i ] ) ;
return 0 ;
}