TopCoder problem "JoshSum" used in TCHS SRM 38 (Division I Level Two)



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

0)
    
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)
    
1
Returns: 1
The first Fibonacci number is 1. The answer is 1.
2)
    
365
Returns: 1692
3)
    
44
Returns: 212
4)
    
98765
Returns: 460892

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8070

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10779&pm=8070

Writer:

vlad_D

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Math