3

Problem 292 - Factorial Trailing Zeroes

 1 year ago
source link: https://www.codeabbey.com/index/forum_topic/26dafd5fbcaf03e3246fa4d86144ab76
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Problem 292 - Factorial Trailing Zeroes

Back to General discussions forum

sam_bandara     2022-08-30 03:18:15

Hello again guys, This time I stucked in the problem 292. To calcualte the factorial I used builtin python function but it takes forever to calculate. Then I used Sterlin Approximate (Read a lot :-) ) to calculate and endup with "OverflowError: (34, 'Result too large')".

math.sqrt(2 * math.pi) * y ** (y + 0.5) * math.exp(-y)

2nd issue is convert the factorial values into n Base. I just used classical division method but it is not the right method to use since there are a lot of divisions and etc.

Could you please someone givi me a hint on how to and where to start?

Cheers, Sam.

Rodion (admin)     2022-08-30 07:47:34
User avatar

Sam, Hi!

This reminds me the story of a person who is selling a piece of forested land, and when asked if he counted trees and total amount of wood in it, feels surprised "how am I supposed to count trees in the forest???"

You are asked about trailing zeroes of factorial, not about factorial itself!

I used builtin python function but it takes forever to calculate

Really, when you see input suspiciously large, you may suspect (without trying) it is done exactly to make direct calculation difficult :)

Then I used Sterlin Approximate

This obviously can't help as it is approximate and you won't have exact trailing digits of a value, right :)

Could you please someone givi me a hint on how to and where to start?

Well, recollect that it is popular interview question, and in its original form (for 100! and decimal system) it is supposed to be solved without paper or computer, straight "in head". Try this and you most probably get upon the idea.

Please login and solve 5 problems to be able to post at forum

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK