Generating large Fibonacci numbers using boost library Last Updated : 08 Apr, 2021 Comments Improve Suggest changes Like Article Like Report In our previous post on fibonacci series, we have seen many approaches to generate fibonacci numbers. In this approach, we shall be generating fibonacci numbers with the help of boost library. The program simply uses the "boost/multiprecision/cpp_int.hpp" boost library in which big_int is defined. The fibonacci numbers beyond the range of long long int can also be generated using the boost library. Below is the C++ implementation to generate fibonacci numbers using the boost library. CPP // C++ implementation to generate large // number of fibonacci series using the // boost multiprecision library #include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> using big_int = boost::multiprecision::cpp_int; using namespace std; // function to generate first n // fibonacci numbers int fib(unsigned int n) { // seed values // 0th and 1st number of the // series are 0 and 1 big_int a = 0; big_int b = 1; cout << "Term 1 is : " << a << endl; cout << "Term 2 is : " << b << endl; for (unsigned int i = 2; i < n; ++i) { const big_int c = a + b; cout << "Term "<< i + 1 << " is : " << c << endl; a = b; b = c; } } // Driver code int main() { unsigned int n = 30; // function calling fib(n); return 0; } Java // Java implementation to generate large // number of fibonacci series using the // boost multiprecision library public class GFG { // function to generate first n // fibonacci numbers static void fib(int n) { // seed values // 0th and 1st number of the // series are 0 and 1 int a = 0; int b = 1; System.out.println("Term 1 is : " + a); System.out.println("Term 2 is : " + b); for (int i = 2; i < n; ++i) { int c = a + b; System.out.println("Term " + (i + 1) + " is : " + c); a = b; b = c; } } // Driver code public static void main(String[] args) { int n = 30; // function calling fib(n); } } // This code is contributed by divyeshrabadiya07. Python3 # Python3 implementation to generate large # number of fibonacci series using the # boost multiprecision library # function to generate first n # fibonacci numbers def fib( n): # seed values # 0th and 1st number of the # series are 0 and 1 a = 0; b = 1; print("Term 1 is : " + str(a)); print("Term 2 is : " + str(b)); for i in range(2, n): c = a + b; print("Term " + str(i + 1) + " is : " + str(c)); a = b; b = c; # Driver code if __name__=='__main__': n = 30; # function calling fib(n); # This code is contributed by rutvik_56. C# // C# implementation to generate large // number of fibonacci series using the // boost multiprecision library using System; class GFG { // function to generate first n // fibonacci numbers static void fib(int n) { // seed values // 0th and 1st number of the // series are 0 and 1 int a = 0; int b = 1; Console.WriteLine("Term 1 is : " + a); Console.WriteLine("Term 2 is : " + b); for (int i = 2; i < n; ++i) { int c = a + b; Console.WriteLine("Term " + (i + 1) + " is : " + c); a = b; b = c; } } // Driver code static void Main() { int n = 30; // function calling fib(n); } } // This code is contributed by divyesh072019 JavaScript <script> // Javascript implementation to generate large // number of fibonacci series using the // boost multiprecision library // function to generate first n // fibonacci numbers function fib(n) { // seed values // 0th and 1st number of the // series are 0 and 1 let a = 0; let b = 1; document.write("Term 1 is : " + a + "</br>"); document.write("Term 2 is : " + b + "</br>"); for (let i = 2; i < n; ++i) { let c = a + b; document.write("Term " + (i + 1) + " is : " + c + "</br>"); a = b; b = c; } } let n = 30; // function calling fib(n); // This code is contributed by mukesh07. </script> Output : Term 1 is : 0 Term 2 is : 1 Term 3 is : 1 Term 4 is : 2 Term 5 is : 3 Term 6 is : 5 Term 7 is : 8 Term 8 is : 13 Term 9 is : 21 Term 10 is : 34 Term 11 is : 55 Term 12 is : 89 Term 13 is : 144 Term 14 is : 233 Term 15 is : 377 Term 16 is : 610 Term 17 is : 987 Term 18 is : 1597 Term 19 is : 2584 Term 20 is : 4181 Term 21 is : 6765 Term 22 is : 10946 Term 23 is : 17711 Term 24 is : 28657 Term 25 is : 46368 Term 26 is : 75025 Term 27 is : 121393 Term 28 is : 196418 Term 29 is : 317811 Term 30 is : 514229 Comment More infoAdvertise with us Next Article Generating large Fibonacci numbers using boost library A ajay0007 Follow Improve Article Tags : Technical Scripter C++ Programs DSA Fibonacci cpp-boost +1 More Practice Tags : Fibonacci Similar Reads C++ Program For Fibonacci Numbers The Fibonacci series is the sequence where each number is the sum of the previous two numbers. The first two numbers of the Fibonacci series are 0 and 1, and they are used to generate the entire series.Examples:Input: 5Output: 5Explanation: As 5 is the 5th Fibonacci number of series 0, 1, 1, 2, 3, 5 5 min read TCS Coding Practice Question | Fibonacci Series Given a number 'n', the task is to print the Fibonacci series using Command Line Arguments. The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ........ In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the re 4 min read Split a Numeric String into Fibonacci Sequence Given a numeric string S representing a large number, the task is to form a Fibonacci Sequence of at least length 3 from the given string. If such a split is not possible, print -1. Examples: Input: S = â5712â Output: 5 7 12 Explanation: Since 5 + 7 = 12, the splits {5}, {7}, {12} forms a Fibonacci 10 min read Sum of Fibonacci numbers at even indexes upto N terms Given a positive integer N, the task is to find the value of F2 + F4 + F6 +.........+ F2n upto N terms where Fi denotes the i-th Fibonacci number.The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...... Examples: Input: n = 5 Outpu 15+ min read Program to find LCM of two Fibonacci Numbers Given here are two positive numbers a and b. The task is to print the least common multiple of a'th and b'th Fibonacci Numbers.The first few Fibonacci Numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ......Note that 0 is considered as 0âth Fibonacci Number.Examples: Input : a = 3, b = 12 Ou 8 min read Like