From c5feea8355a86d2ffd86a43854cf289b951547cb Mon Sep 17 00:00:00 2001 From: Nirali Sahoo <58680652+nizz009@users.noreply.github.com> Date: Fri, 23 Oct 2020 12:27:17 +0530 Subject: [PATCH 1/2] Uploaded program-21 Addition of Program-21 in C++ directory which aims to find the last digit of partial Fibonacci Series. --- C++/Program-21/README.md | 26 ++++++++++++++++++++++++++ C++/Program-21/program.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 C++/Program-21/README.md create mode 100644 C++/Program-21/program.cpp diff --git a/C++/Program-21/README.md b/C++/Program-21/README.md new file mode 100644 index 00000000..82aa3347 --- /dev/null +++ b/C++/Program-21/README.md @@ -0,0 +1,26 @@ +#Last digit of sum of partial Fibonacci Series + +##Problem statement: +Given two non-negative integers m and n, where m <= n, find the last digit of the sum *Fm + Fm+1 + .... + Fn* + +###Input: +Two non negative intergers m and n, such that m <= n. + +###Output: +The last digit of the sum of Fibonacci series starting from *Fm* to *Fn*. + +###Example: + +*Input:* +``` +3 7 +``` +*Output:* +``` +1 +``` +*Explanation:* +``` +𝐹3 + 𝐹4 + 𝐹5 + 𝐹6 + 𝐹7 = 2 + 3 + 5 + 8 + 13 = 31 +Last digit of 31 = 1 +``` diff --git a/C++/Program-21/program.cpp b/C++/Program-21/program.cpp new file mode 100644 index 00000000..52bd1d2d --- /dev/null +++ b/C++/Program-21/program.cpp @@ -0,0 +1,37 @@ +/* Compute the last digit of the sum of partial Fibonacci series. (Given two non-negative integers m and n, where m <= n, find the last digit of the sum Fm + Fm+1 + .... + Fn) */ + +#include +using namespace std; +typedef long long int ll; + +void solve() +{ + ll n = 0, m = 0; + int b[60] = {0, 1, 2, 4, 7, 2, 0, 3, 4, 8, 3, 2, 6, 9, 6, 6, 3, 0, 4, 5, 0, 6, 7, 4, 2, 7, 0, 8, 9, 8, 8, 7, 6, 4, 1, 6, 8, 5, 4, 0, 5, 6, 2, 9, 2, 2, 5, 8, 4, 3, 8, 2, 1, 4, 6, 1, 8, 0, 9, 0}; + int i = 0, j = 0, sum = 0; + + cin >> n >> m; + + i = (n-1) % 60; + j = m % 60; + + if(b[j] >= b[i]) + { + cout << b[j] - b[i] << "\n"; + } + else + { + b[j] += 10; + cout << b[j] - b[i] << "\n"; + } +} + +int main() +{ + //for fast input output + ios_base::sync_with_stdio(false);cin.tie(NULL); + + solve(); + + return 0; +} \ No newline at end of file From cd0fb12c9a2a9ec74ff184e9bd7839fecca36fc2 Mon Sep 17 00:00:00 2001 From: Nirali Sahoo <58680652+nizz009@users.noreply.github.com> Date: Fri, 23 Oct 2020 12:28:02 +0530 Subject: [PATCH 2/2] Update README.md --- C++/Program-21/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/C++/Program-21/README.md b/C++/Program-21/README.md index 82aa3347..2b4cfbeb 100644 --- a/C++/Program-21/README.md +++ b/C++/Program-21/README.md @@ -1,15 +1,15 @@ -#Last digit of sum of partial Fibonacci Series +# Last digit of sum of partial Fibonacci Series -##Problem statement: +## Problem statement: Given two non-negative integers m and n, where m <= n, find the last digit of the sum *Fm + Fm+1 + .... + Fn* -###Input: +### Input: Two non negative intergers m and n, such that m <= n. -###Output: +### Output: The last digit of the sum of Fibonacci series starting from *Fm* to *Fn*. -###Example: +### Example: *Input:* ```