Problem 684
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
- Kenya_A
- Posts: 3
- Joined: Sat Dec 12, 2015 4:09 am
Problem 684
Problem 684 (View Problem)
Hi,
I haven't solved this yet, but I noticed that the example number has the same quotient and remainder when divisible by 9, so it's impossible to tell using it alone if you have made a mistake in entering one of these into the solution.
I can't solve it because, try I might, I haven't found enough tricks to calculating the numbers in a reasonable time and without overflow. I have done modulo operations after each addition and multiplication, tried (and abandoned in favour of built-ins) a method of modular exponentiation which cancels out much of the multiplying by setting the relevant exponents mod x to 1, and found closed form expressions for the sums. The limit is the exponentiations. What, besides maybe the F's thm, can speed this up? It may be finished yet by this time next year at this rate.
Hi,
I haven't solved this yet, but I noticed that the example number has the same quotient and remainder when divisible by 9, so it's impossible to tell using it alone if you have made a mistake in entering one of these into the solution.
I can't solve it because, try I might, I haven't found enough tricks to calculating the numbers in a reasonable time and without overflow. I have done modulo operations after each addition and multiplication, tried (and abandoned in favour of built-ins) a method of modular exponentiation which cancels out much of the multiplying by setting the relevant exponents mod x to 1, and found closed form expressions for the sums. The limit is the exponentiations. What, besides maybe the F's thm, can speed this up? It may be finished yet by this time next year at this rate.

- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 684
In the big pink box at the top of the page it reads:
'Don't ask for hints how to solve a problem'
'Don't ask for hints how to solve a problem'

War ruins the life and health of untold numbers of innocent children.
- nicolas.patrois
- Posts: 118
- Joined: Fri Jul 26, 2013 4:54 pm
- Contact:
Re: Problem 684
Hi,
Is sum from i=2 to i=30 S(fi) (mod 1_000_000_007) equal to xxxxxxxxx? <value snipped by moderator>
Thank you.
Is sum from i=2 to i=30 S(fi) (mod 1_000_000_007) equal to xxxxxxxxx? <value snipped by moderator>
Thank you.

-
RudiGj
- Posts: 1
- Joined: Fri Jan 03, 2020 11:59 pm
Re: Problem 684
Just need a little bit of clarification on this problem.
Do you have to find the smallest digit sum for each term of the fibonacci sequence from the 2nd to the 90th?
Therefore the answer would be:
digitsum(1) + digitsum(2) + digitsum(3) + digitsum(5) + digitsum(8) + .... + digitsum(n) until the 90th term?
Do you have to find the smallest digit sum for each term of the fibonacci sequence from the 2nd to the 90th?
Therefore the answer would be:
digitsum(1) + digitsum(2) + digitsum(3) + digitsum(5) + digitsum(8) + .... + digitsum(n) until the 90th term?
- RobertStanforth
- Administrator
- Posts: 2666
- Joined: Mon Dec 30, 2013 11:25 pm
Re: Problem 684
No, that is not correct. $S(n)$ is not digitsum.RudiGj wrote: Sat Jan 04, 2020 12:04 am Do you have to find the smallest digit sum for each term of the fibonacci sequence from the 2nd to the 90th?
Instead, $s(n)$ is the inverse digit sum, so $\mathrm{digitsum}(s(n)) = n$.
Note also that $S$ is the sum of $s$.
So, (given a Fibonacci number $f_i$), you have to find the smallest number whose digit sum is $n$, for each number $n$ up to $f_i$. Their sum gives you $S(f_i)$.
Then the answer would be: $S(1) + S(2) + S(3) + S(5) + S(8) + ... + S(f_{90})$.
-
AWR
- Posts: 2
- Joined: Mon Apr 13, 2020 12:59 pm
Re: Problem 684
Just solved this after quite a bit of head scratching.
Seems a bit hard for a Difficulty rating of 5%?
Or maybe I'm just a bit thick?
Andrew
Seems a bit hard for a Difficulty rating of 5%?
Or maybe I'm just a bit thick?
Andrew
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 684
Please have a look at the fastest solvers table....

War ruins the life and health of untold numbers of innocent children.
-
AWR
- Posts: 2
- Joined: Mon Apr 13, 2020 12:59 pm
Re: Problem 684
True, there are some quick solutions but they all revolve around figuring out the mathematics. Once done the coding is simple. How do you balance mathematical know-how against coding ability? Problem 243 was similar - it was easy if you got your head around the maths. (I was much more familiar with the mathematics required for that problem!)
I still wouldn't put this problem in the same category with problems 53 and 55 for example!
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 684
The simple answer is: the difficulty assessment is automatically calculated based on solver times.
We've no better way to do it..
We've no better way to do it..

War ruins the life and health of untold numbers of innocent children.
- yourmaths
- Posts: 47
- Joined: Mon Aug 25, 2014 11:00 am
Re: Problem 684
I have what I think is a correct algorithm for this problem but my answer is not being accepted.
$S(f_2) + S(f_3) + ... + S(f_{90})$
Is this right? From the problem description the answer should be given byRobertStanforth wrote: Sat Jan 04, 2020 9:04 am So, (given a Fibonacci number $f_i$), you have to find the smallest number whose digit sum is $n$, for each number $n$ up to $f_i$. Their sum gives you $S(f_i)$.
Then the answer would be: $S(1) + S(2) + S(3) + S(5) + S(8) + ... + S(f_{90})$.
$S(f_2) + S(f_3) + ... + S(f_{90})$
level = lambda number_solved: number_solved // 25


- Animus
- Administrator
- Posts: 1987
- Joined: Sat Aug 16, 2014 1:23 pm
- yourmaths
- Posts: 47
- Joined: Mon Aug 25, 2014 11:00 am
Re: Problem 684
All good. I had a frustratingly hard-to-find typo. 
level = lambda number_solved: number_solved // 25


-
codingclubwaseesucks
- Posts: 1
- Joined: Sat Jul 04, 2020 6:50 pm
Re: Problem 684
Could you clarify what you mean about "Instead, s(n) is the inverse digit sum, so digitsum(s(n))=n"?
What is an Inverse Digit Sum?
What is an Inverse Digit Sum?
RobertStanforth wrote: Sat Jan 04, 2020 9:04 amNo, that is not correct. $S(n)$ is not digitsum.RudiGj wrote: Sat Jan 04, 2020 12:04 am Do you have to find the smallest digit sum for each term of the fibonacci sequence from the 2nd to the 90th?
Instead, $s(n)$ is the inverse digit sum, so $\mathrm{digitsum}(s(n)) = n$.
Note also that $S$ is the sum of $s$.
So, (given a Fibonacci number $f_i$), you have to find the smallest number whose digit sum is $n$, for each number $n$ up to $f_i$. Their sum gives you $S(f_i)$.
Then the answer would be: $S(1) + S(2) + S(3) + S(5) + S(8) + ... + S(f_{90})$.
- dawghaus4
- Posts: 56
- Joined: Fri Nov 29, 2013 2:22 am
Re: Problem 684
Let digitsum(x) be the sum of the digits of the number x. For example, digitsum(19) = 10. An inverse function would reverse that. If the sum of the digits is 10, what is the number. Without the restriction, "the smallest number," there would be lots answers With the restriction, we can say 19 is the smallest number with a digit sum of 10. That is what is meant by an Inverse Digit Sum.codingclubwaseesucks wrote: Sat Jul 04, 2020 6:51 pm Could you clarify what you mean about "Instead, s(n) is the inverse digit sum, so digitsum(s(n))=n"?
What is an Inverse Digit Sum?
In the problem, n is the digit sum, and s(n) is the smallest number whose digits sum to n. digitsum(19) = 10 and s(10) = 19.
Hope that helps.
- PurpleBlu3s
- Posts: 75
- Joined: Mon Sep 19, 2011 6:49 pm
Re: Problem 684
Generalise the problem such that F(N) = S(f2) + ... + S(fN).
I have a (slow) brute force algorithm, a medium algorithm and a fast algorithm. They all agree as far as I can push the slower ones, which is up to F(22) for the brute force and F(46) for the medium algorithm.
The brute force and medium algorithm both agree with S(20) = 1074 (the fast one only works on Fibonacci inputs).
My answer for F(90) is apparently not correct.
Is anyone willing to verify a couple of intermediate results?
I have a (slow) brute force algorithm, a medium algorithm and a fast algorithm. They all agree as far as I can push the slower ones, which is up to F(22) for the brute force and F(46) for the medium algorithm.
The brute force and medium algorithm both agree with S(20) = 1074 (the fast one only works on Fibonacci inputs).
My answer for F(90) is apparently not correct.
Is anyone willing to verify a couple of intermediate results?

- gaufowl
- Posts: 6
- Joined: Tue Sep 22, 2020 10:36 pm
- Location: MD,USA
Re: Problem 684
I'd be willing to do some cross verification with you. I haven't solved it yet either but I believe I have it running correctly so far up to the mid-30 of fibonacci numbers. Feel free to pm me on here.PurpleBlu3s wrote: Thu Dec 31, 2020 6:15 pm Is anyone willing to verify a couple of intermediate results?

1691991_rIEOKCNEDBtm7EzRUeWtIZDvhFNxQVp1
-
pjt33
- Posts: 140
- Joined: Mon Oct 06, 2008 6:14 pm
Re: Problem 684
I think it's a legitimate hint to say that there's nothing special about Fibonacci inputs. My best guess is that the question asks for the particular Fibonacci-based sum that it does as a way of making the calculation expensive enough to trip up brute force solutions without using inputs that don't fit in a 64-bit integer.PurpleBlu3s wrote: Thu Dec 31, 2020 6:15 pm The brute force and medium algorithm both agree with S(20) = 1074 (the fast one only works on Fibonacci inputs).
-
Rock5
- Posts: 1
- Joined: Tue Dec 28, 2021 3:05 pm
Re: Problem 684
This is way more difficult than 5%.
After spending about a week on this, this will be the first 5% difficulty challenge I'm going to have to give up on. I've completed 68 of them so far.
Given that it's impossible for the s(n) function to generate output with the high Fibonacci numbers as input without running out of memory, and there is no direct relation between n and the s(n) output, it's obvious that there needs to be some sort of modulo shenanigans happening in the s function that I can't figure out. I suspect that proficiently, mathematically inclined people, that are already familiar with this sort of problem, will be able to solve it. Being primarily a programmer that likes math, this ones impossible for me.
You can also tell it's difficult as only 2145 people have solved it, whereas most 5% challenges are completed by about 60,000 people.
If there is an automated process for selecting the difficulty, perhaps the process needs to be examined.
After spending about a week on this, this will be the first 5% difficulty challenge I'm going to have to give up on. I've completed 68 of them so far.
Given that it's impossible for the s(n) function to generate output with the high Fibonacci numbers as input without running out of memory, and there is no direct relation between n and the s(n) output, it's obvious that there needs to be some sort of modulo shenanigans happening in the s function that I can't figure out. I suspect that proficiently, mathematically inclined people, that are already familiar with this sort of problem, will be able to solve it. Being primarily a programmer that likes math, this ones impossible for me.
You can also tell it's difficult as only 2145 people have solved it, whereas most 5% challenges are completed by about 60,000 people.
If there is an automated process for selecting the difficulty, perhaps the process needs to be examined.
-
DJohn
- Posts: 90
- Joined: Sat Oct 11, 2008 12:24 pm
Re: Problem 684
The other 5% problems with tens of thousands of solvers are many years older than this. They've had a lot more time to accumulate. Other 5% problems of a similar age (686: 2733, 700: 2380, 719: 2082, 751: 1193, at the time of posting) have similar numbers of solvers, steadily decreasing as they get younger. 684 is slightly below the curve, but not by much. It is perhaps at the hard end of 5%, but it isn't a 10% problem.
Difficulty is very subjective, and depends greatly on the knowledge of the solver. I remember this one being fairly simple, but annoying to implement. Other people will have had other experiences of it.
Difficulty is very subjective, and depends greatly on the knowledge of the solver. I remember this one being fairly simple, but annoying to implement. Other people will have had other experiences of it.
-
maujjy
- Posts: 4
- Joined: Wed Jan 05, 2022 7:15 pm
Re: Problem 684
Hi, I am having exactly this problem. My brute-force and slick algorithms agree up to F(30) as PurpleBlu3s puts it, and my brute-force really is the most naive thing (I suspect, I know what he means by "medium", I haven't tried that but I'll have a go now to see if I can get up to 46) but I have F(90) wrong. Is anyone willing to see if they agree with my value of F(30)?PurpleBlu3s wrote: Thu Dec 31, 2020 6:15 pm Generalise the problem such that F(N) = S(f2) + ... + S(fN).
I have a (slow) brute force algorithm, a medium algorithm and a fast algorithm. They all agree as far as I can push the slower ones, which is up to F(22) for the brute force and F(46) for the medium algorithm.
The brute force and medium algorithm both agree with S(20) = 1074 (the fast one only works on Fibonacci inputs).
My answer for F(90) is apparently not correct.
Is anyone willing to verify a couple of intermediate results?
EDIT: It was my own sloppiness, I overlooked a decision I made that introduced precision errors later on...All good now!