It's n-onacci this time!

14 14 and 197 197 are somewhat special numbers. How?

  • 14 : 14: Number of digits in 14 14 is 2 2 . Trying to make a n-onacci sequence with n = 2 n=2 1 , 4 , ( 1 + 4 = ) 5 , ( 4 + 5 = ) 9 , ( 5 + 9 = ) 14... 1,4,(1+4=)5,(4+5=)9,(5+9=)14... Thus, 14 lies in 2-onacci sequence started from its digits.

  • 197: Number of digits in 197 197 is 3 3 . Repeating the above steps with n = 3 n=3 , 1 , 9 , 7 , ( 1 + 9 + 7 = ) 17 , ( 9 + 7 + 17 = ) 33 , ( 7 + 17 + 33 = ) 57 , ( 17 + 33 + 57 = ) 107 , ( 33 + 57 + 107 ) = 197... 1,9,7,(1+9+7=)17,(9+7+17=)33,(7+17+33=)57 \\ ,(17+33+57=)107,(33+57+107)=197... Thus, 197 lies in 3-onacci sequence started from its digits.

Such special numbers are called Keith Numbers , with 14 14 being the smallest number that satisfy such property.

Calculate the sum of the 20th and 40th Keith Numbers.

Details and Assumptions :

  • n-onacci \text{n-onacci} is a name given by me only.

  • Fibonacci sequence \text{Fibonacci sequence} is an example of 2-onacci sequence starting with [ 0 , 1 ] [0,1] .

  • Tribonacci sequence \text{Tribonacci sequence} is an example of 3-onacci sequence starting with [ 0 , 0 , 1 ] [0,0,1] .

Here are My CS Problems .


The answer is 129606356.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

David Holcer
Apr 7, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def k (n):
    array=[]
    for i in str(n):
        array.append(int(i))
    while True:
        if array[-1]>n:
            break
        else:
            summ=0
            for i in range(1,len(str(n))+1):
                summ+=array[-i]
            array.append(summ)
    if n in array:
        return True
keith=[]
c=14
while True:
    if len(keith)==40:
        break
    else:
        if k(c):
            keith.append(c)
    c+=1
print keith[19]+keith[-1]        

Main code is in the function k which similar to fibonacci, adds the previous terms of series based on length of given number and returns true if number in series, breaks if last number greater than given number.

Kartik Sharma
Apr 7, 2015

PYTHON

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
>>> def pr(a,n):
    K = []
    L = list(str(a))
    S = 0
    while (S<n):
        S = 0
        O = L[::-1]
        for i in range(len(str(a))):
            S += int(O[i])
        L.append(str(S))
        K.append(S)
    return K
>>> def Keith(n):
    F = pr(n,n)
    X = F[::-1]
    if X[0]==n:
        return True
    else:
        return False

After this all we need to do is some for loops or even while loops(but while loop will take a lot of time without any result). So, more preferable is the former as writing any bound and then getting result is exciting.

CAUTION : But truly, it is very difficult to have a quick result. It would take some time.

I don't think this is the correct solution!

Kartik Sharma - 6 years, 2 months ago

Log in to reply

This one is (almost) same as mine. I'm also looking for a better one.

Pranjal Jain - 6 years, 2 months ago
James Moors
Aug 5, 2015

Python:

n = 10
K = list()
while len(K) < 40:
n+=1
s = 0
nums = [int(x) for x in str(n)] #seperate the digits of n
while s<n:
    s = sum(nums) #sum the elements of nums
    nums = nums[1:] + [s,] #lose first element, shunt everything over, tack sum to end
if s == n: 
    K.append(n)
    print "{}: {}".format(len(K),n) #show progress

print "{} + {} = {}".format(K[19], K[39], K[19]+K[39])

After the first 30-odd, this takes its sweet time; I made it show each individual Keith number so I knew it was doing something...

Mikael Marcondes
Apr 8, 2015

You should make a note, with no OEIS allowed C:

? Sorry, I couldn't got you. Can you explain?

Pranjal Jain - 6 years, 2 months ago

Log in to reply

OEIS, The Online Encyclopedia of Integer Series, hahaha ;)

Mikael Marcondes - 6 years, 2 months ago

Log in to reply

Oh! Lolol, well, no one can stop cheaters. ¨ \ddot\smile

Pranjal Jain - 6 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...