Problem Statement
Josh thought he would be cooler if he had his own secret sum. The Josh Sum of an integer n is the sum of the last digit of each of the first n terms of the Fibonacci series. The Fibonacci series is : 1,1,2,3,5,etc. The i-th term of the series is equal to the sum of the (i-1)-th term and (i-2)-th term, and the first and second terms are 1. The Josh Sum for n = 7 is 1 + 1 + 2 + 3 + 5 + 8 + 3 = 23. Given n, return its Josh Sum.
Definition
- Class:
- JoshSum
- Method:
- getJoshSum
- Parameters:
- int
- Returns:
- int
- Method signature:
- int getJoshSum(int n)
- (be sure your method is public)
Constraints
- n will be between 1 and 100000, inclusive.
Examples
7
Returns: 23
The first 7 Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13; therefore the answer is 1 + 1 + 2 + 3 + 5 + 8 + 3 = 23.1
Returns: 1
The first Fibonacci number is 1. The answer is 1.365
Returns: 1692
44
Returns: 212
98765
Returns: 460892