Fibonacci Sequence [1]

The n n th term of sequence can be written as following F n = F n 1 + F n 2 F_n = F_{n-1} +F_{n-2} , with F 1 = 1 F_{1}=1 and F 2 = 1 F_{2}=1 .

For the question part: F 9 = 34 F_{9}=34 and sum of its digits is 7.

Find the sum of digits of F 99 F_{99}

Bonus: Can you find the digit sum of F 9999 F_{9999} ?


The answer is 101.

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.

2 solutions

Amal Hari
Feb 18, 2019

This was part of my assignment but i decided to extend it a bit (You can find F 9999 F_{9999} using this )

import java.util. ; import java.math. ; public class Fibonacci {

public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    String dec="Y";
    System.out.println("Enter number of terms in fibonacci sequence:");
    int size=in.nextInt();
    in.nextLine();
    int stop1=0;
    int stopm=0;
    while(stopm==0) {

        while(size>0 && stop1==0) {

            BigInteger[] fibs =new BigInteger[size];
            if (size==1) {
                fibs[0]=BigInteger.valueOf(1);
            }
            else if(size==2) {
                fibs[0]=BigInteger.valueOf(1);
                fibs[1]=BigInteger.valueOf(1);
            }
            else {
                fibs[0]=BigInteger.valueOf(1);
                fibs[1]=BigInteger.valueOf(1);
                int r=2;
                while(r<size) {

                    fibs[r]=fibs[r-1].add(fibs[r-2]);
                    r++;
                }
            }

            System.out.println("The last number of the sequence is "+ fibs[size-1]);
            String g=new String(fibs[size-1].toString());
            int lengthg=g.length();
            int sum=0;
            int start=0;
            while(start<lengthg) {

                sum+= g.charAt(start)-'0' ;
                start++;
            }
            System.out.println("Sum of digits of the number is: "+sum);
            System.out.println("Would you like to continue?(Y/N)");
            dec=in.nextLine();
            if (dec.equals("Y")) {
                System.out.println("Enter size of fibonacci sequence:");
                size=in.nextInt();
                in.nextLine();
            }
            else {
                System.out.println("Bye!");
                stop1=100;
                stopm=1;
            }

        }

    }
    in.close();
}

}

I believe that F 9999 = 9385 F_{9999} = 9385 . This made me curious about the numbers n n which are equal to the digit sum of F n F_{n} . The list is given here . It's unknown if the list is infinite or not, but the largest known value for n n is 2222 2222 .

Brian Charlesworth - 2 years, 3 months ago

I tried to find one higher than 2222 it seems like a far stretch.

What i found is here

Here is link to the code i used code

Amal Hari - 2 years, 3 months ago

Log in to reply

Great! Thanks for working on my follow-up question. :)

Brian Charlesworth - 2 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...