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
1
Returns: 1
2
Returns: 2
100000
Returns: 466675
5005
Returns: 23347
50007
Returns: 233358
75009
Returns: 350028
133
Returns: 609
2076
Returns: 9688
20098
Returns: 93799
10876
Returns: 50743
80908
Returns: 377559
99999
Returns: 466670
98789
Returns: 461008
67876
Returns: 316743
3
Returns: 4
4
Returns: 7
5
Returns: 12
99960
Returns: 466480
99961
Returns: 466481
99959
Returns: 466480