346 Long Decimal Fractions

Back to General discussions forum

omsarmiento1953     2023-12-13 03:48:21

I have a solution but my solution takes too long. My programming language is Julia. I use BigInt, divrem function, exponentiation and modulo to get the last digit. For the 18 items I need to solve I am in item 15 and it's taking forever. Can anyone recommend or provide a clue on what's a better way to solve this problem?

Rodion (admin)     2023-12-13 04:11:40
User avatar

This problem was mistakenly marked with tag simple, but it is definitely from puzzles section, so I changed the tag.

It is valuable to give experience of assessing calculation complexity before trying to solve. To put it simple, author intentionally picked such limits that "straightforward" solution with long arithmetics is guaranteed to stuck in any language. As usual with puzzles, this task mainly makes sense if you find its cunning solution yourself. So perhaps it's better to think a bit more on it ourselves (I haven't solved it too yet) and skip for now if no enlightenment comes. Perhaps on the other attempt in a week or a month it may suddenly crack :)

omsarmiento1953     2023-12-13 05:11:22

It will be simple if the fractions are no larger than 10 digits.

zelevin     2023-12-13 05:44:21

True. But that would sort of defeat the point of the problem, which is to make the solver think.

Rodion (admin)     2023-12-13 06:47:31
User avatar

at least it is easy to understand where to start thinking from - reading about decimal fractions, their periods, conversion etc. The limit of 10^18 in the problem statement should instantly hint such long value won't fit any computer memory, neither the program could do so many iterations in dozens years.

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