Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3333072
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:45:23+00:00 2026-05-17T23:45:23+00:00

We all know fibonacci series, when k = 2. I.e.: 1,1,2,3,5,8,13 But this is

  • 0

We all know fibonacci series, when k = 2.

I.e.: 1,1,2,3,5,8,13

But this is the 2-fibonacci. Like this, I can count the third-fibonacci:

1,1,2,4,7,13,24

And the 4-fibonacci:

1,1,2,4,8,15,29

…and so goes on

What I’m asking is an algorithm to calculate an ‘n’ element inside a k-fibonacci series.

Like this: if I ask for fibonacci(n=5,k=4), the result should be: 8, i.e. the fifth element inside the 4-fibonacci series.

I didn’t found it anywhere web. A resouce to help could be mathworld

Anyone? And if you know python, I prefer. But if not, any language or algorithm can help.

Tip I think that can help:
Let’s analyze the k-fibonacci series, where k will go from 1 to 5

k    fibonacci series

1    1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, ...
2    1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
3    1, 1, 2, 4, 7, 13, 24, 44, 81, ...
4    1, 1, 2, 4, 8, 15, 29, 56, 108, ...
5    1, 1, 2, 4, 8, 16, 31, 61, 120, ...

Analyzing this, we can see that the array [0:k] on the k-fibonacci series is equal to the
previous fibonacci series, and it goes on till the k=1

i.e. (I’ll try to show, but I’m not finding the right way to say it):

k    fibonacci series

1    1, 
2    1, 1, 
3    1, 1, 2, 
4    1, 1, 2, 4, 
5    1, 1, 2, 4, 8, 

Hope I’ve helped somehow to solve this.

[SOLUTION in python (if anyone needs)]

class Fibonacci:

    def __init__(self, k):
        self.cache = []
        self.k = k

        #Bootstrap the cache
        self.cache.append(1)
        for i in range(1,k+1):
            self.cache.append(1 << (i-1))

    def fib(self, n):
        #Extend cache until it includes value for n.
        #(If we've already computed a value for n, we won't loop at all.)
        for i in range(len(self.cache), n+1):
            self.cache.append(2 * self.cache[i-1] - self.cache[i-self.k-1])

        return self.cache[n]


#example for k = 5
if __name__ == '__main__':
    k = 5
    f = Fibonacci(k)
    for i in range(10):
        print f.fib(i),
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:45:23+00:00Added an answer on May 17, 2026 at 11:45 pm

    Here is an iterative solution building on Ambers answer:

    class Fibonacci {
    
        List<Integer> cache = new ArrayList<Integer>();
        final int K;
    
        public Fibonacci(int k) {
            this.K = k;
    
            // Bootstrap the cache
            cache.add(1);
            for (int i = 1; i <= k; i++)
                cache.add(1 << (i-1));
        }
    
        public long fib(int n) {
    
            // Extend cache until it includes value for n.
            // (If we've already computed a value for n, we won't loop at all.)
            for (int i = cache.size(); i <= n; i++)
                cache.add(2 * cache.get(i-1) - cache.get(i-K-1));
    
            // Return cached value.
            return cache.get(n);
        }
    }
    

    A test looks like this:

    public class Main {
        public static void main(String[] args) {
            System.out.println("k     fibonacci series");
    
            for (int k = 1; k <= 5; k++) {
                System.out.print(k + "     ");
    
                Fibonacci f = new Fibonacci(k);
                for (int i = 0; i < 10; i++)
                    System.out.print(f.fib(i) + ", ");
                System.out.println("...");
    
            }
        }
    }
    

    And prints

    k     fibonacci series
    1     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
    2     1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
    3     1, 1, 2, 4, 7, 13, 24, 44, 81, 149, ...
    4     1, 1, 2, 4, 8, 15, 29, 56, 108, 208, ...
    5     1, 1, 2, 4, 8, 16, 31, 61, 120, 236, ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We all know you can't do things like this: int a = 7; new
We all know calls like this: list($a, $b) = explode(':', 'A:B'); But how to
We all know to set canvas's context property like this: ctx.textBaseline = top; ctx.shadowColor
We all know that a readonly reference type variable's reference can't change, but the
We all know about semaphore and critical section problem. In pthreads, this can be
We all know doing something like this is bad: <ul> <li>Item</li> <li>Item</li> ... 500
We all know the effects that lots of thrown exceptions can have over the
We all know it - this is the reading that lists the changes brought
As we all know,we can use such api as LockWorkStation() in user32.dll to lock
You all know the You've got new answers! notification bar on SO. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.