This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Project Euler - Problem 20

Aashu Aggarwal
Greenhorn
Posts: 4
Problem statement -

n! means n (n 1) ... 3 2 1

For example, 10! = 10 9 ... 3 2 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

I am trying to solve it but 100! is big even for long. I thought i can try to break the factorial in parts and then solve it but still in end i have to multiply all the results which overshoot the long.

Looking for some guidance.

Thanks,
Aashu

fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
• 2
Check the java API for something that might let you work with a Big Integer...

Aashu Aggarwal
Greenhorn
Posts: 4
fred rosenberger wrote:Check the java API for something that might let you work with a Big Integer...

Thanks Fred. That worked perfectly :-)

 It is sorta covered in the JavaRanch Style Guide.