Pizza-No!

The Fibonacci numbers are F 1 = 1 , F 2 = 1 , F 3 = 2 , F 4 = 3 , F 5 = 5 , F 6 = 8 , F 7 = 13 F_1=1 , F_2=1 , F_3=2 , F_4=3 , F_5=5 , F_6=8 , F_7=13

where the first two are both equal to 1 1 , and from then on, each one is the sum of the two preceding it. Of the first 2324 2324 Fibonacci numbers, how many have 3 3 as their last digit?


The answer is 309.

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.

11 solutions

Dhruv Baid
Dec 26, 2013

Examining the last digits of the numbers in the Fibonacci Sequence, we can see very clearly that they are periodic with period 60 (the last digits repeat themselves every 60 numbers). Hence, we can immediately conclude that, since 2324 = ( 38 × 60 ) + 44 2324 = (38 \times 60) + 44 , there are ( 38 × 8 ) + 5 = 309 (38 \times 8) + 5 = \boxed {309} Fibonacci numbers (of the first 2324 2324 ) which have 3 3 as their last digit.

In fact, we can easily establish a general formula: every 60 60 consecutive Fibonacci numbers will have 8 8 numbers ending in a certain digit x x 1 ( m o d 2 ) x | x \cong 1 (mod 2) and 4 4 numbers ending in a digit y y 0 ( m o d 2 ) y | y \cong 0 (mod 2) , where 0 x , y 9 0 \leq x,y \leq 9 .

Note that the Fibonacci sequence is an immediately periodic sequence mod any number m m [thanks to Calvin Lin].

Rahul Saha - 7 years, 5 months ago

you actually write 60 unit digits... omg...

Hai Nam Le - 7 years, 3 months ago

Log in to reply

me too ,just the units

math man - 6 years, 12 months ago
Ivan Koswara
Dec 26, 2013

Python one-liner that is pretty much unreadable:

>>> [reduce(lambda x, _: (x[1] % 10, (x[0]+x[1]) % 10), range(i), (1,1))[0] for i in range(2324)].count(3)
309

A more mathematical approach :

Observe that the last digits of the Fibonacci sequence repeats. This is easy to notice: There are only 100 100 (read: a finite number) pairs of last digits of F n 1 , F n 2 F_{n-1}, F_{n-2} , and the sequence of the last digits is uniquely determined from each pair. So once the pair repeats, we have found the cycle.

By bruteforcing from 1 , 1 1,1 , we see that the sequence of last digits repeat with period 60 60 . We can thus mark the terms that have a last digit of 3 3 . In this case, there are 8 8 such terms in a cycle, and 5 5 terms appear up to the 44 44 th term.

Since 2324 = 38 60 + 44 2324 = 38 \cdot 60 + 44 , we know that there are 38 8 38 \cdot 8 terms ending with a 3 3 in the first 38 60 38 \cdot 60 terms, plus 5 5 more for the last 44 44 terms, thus we have 38 8 + 5 = 309 38 \cdot 8 + 5 = \boxed{309} terms ending with 3 3 among the first 2324 2324 Fibonacci numbers.

nice... but can u help me ..whats wrong with this c code...int i,o=1,p=1,q,sum=0; for(i=0; i<2322; i++) { q=o+p; o=p; p=q; if(p%10==3) sum++; } printf("%d\n", sum); return 0;

Surya Teja Cheedella - 7 years, 5 months ago

Log in to reply

In C++, you might get an overflow. The 47th Fibonacci term is 2971215073 , which exceeds the capacity of int (only 2147483647 ), and thus you get something like -1323752223 instead. Furthermore, this is compounded with the fact that C++'s modulo operator uses the same sign as the dividend (for example, -4 % 3 = -1 and not 2 ). This causes a lot of weird things.

As a simple fix, just note that ( a + b ) m o d 10 = ( ( a m o d 10 ) + ( b m o d 10 ) ) m o d 10 (a+b) \bmod 10 = ((a \bmod 10) + (b \bmod 10)) \bmod 10 , and so you can do the modulo operation on q = o+p; instead (making it q = (o+p) % 10; ).

Ivan Koswara - 7 years, 5 months ago

That one liner is cool,Ive seen reduce used before but what's the __: about?

Thaddeus Abiy - 7 years, 4 months ago

Log in to reply

_ is a valid variable name in Python. Generally, you use _ when you don't care about its value, just that it needs to be present for some reason. : is part of the lambda construct: lambda [variables]: [result] .

Ivan Koswara - 7 years, 4 months ago
Raj Magesh
Dec 26, 2013

We start listing the last digits of the first several Fibonacci numbers (this is not as long as it sounds):

1 , 1 , 2 , ( 3 ) , 5 , 8 , ( 3 ) , 1 , 4 , 5 , 9 , 4 , ( 3 ) , 7 , 0 , 7 , 7 , 4 , 1 , 5 , 6 , 1 , 7 , 8 , 5 , ( 3 ) , 8 , 1 , 9 , 0 , 9 , 9 , 8 , 7 , 5 , 2 , 7 , 9 , 6 , 5 , 1 , 6 , 7 , ( 3 ) , 0 , ( 3 ) , ( 3 ) , 6 , 9 , 5 , 4 , 9 , ( 3 ) , 2 , 5 , 7 , 2 , 9 , 1 , 0 , ( 1 , 1 , 2 , 3 , . . . . ) \begin{aligned}1, 1, 2, (3), 5, 8, (3), 1, 4, 5, 9, 4, (3), 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5, (3), 8, 1, 9, 0, 9, 9, 8, \\7, 5, 2, 7, 9, 6, 5, 1, 6, 7, (3), 0, (3), (3), 6, 9, 5, 4, 9, (3), 2, 5, 7, 2, 9, 1, 0, \left(1, 1, 2, 3, ....\right)\end{aligned}

We notice that the pattern repeats every 60 digits. For every 60 digits, there are eight 3s. For every 60 Fibonacci numbers, there are 8 Fibonacci numbers ending with three. From here, the rest of the problem is simple.

2324 ÷ 60 = 38 R 44 2324 \div 60 = 38 R 44

There are 38 complete sets of 8 3s and 44 extra digits. We see from the above list that the first 44 digits of the sequence contain five 3s.

Hence, the total number of Fibonacci numbers ending with 3 is given by:

38 × 8 + 5 = 309 38 \times 8 + 5 = \boxed{309}

Scott Kominers
Feb 14, 2014

This problem can be solved with the following Mathematica command: Total[Array[If[Mod[Fibonacci[#1], 10] == 3, 1, 0] &, {2324}]] .

That said, this problem makes us think about the period of the Fibonacci numbers modulo m m -- a fascinating, well-studied number-theoretic object called the Pisano period . In the case m = 10 m=10 , the Pisano period is 60 60 ; an alternate solution thus proceeds from the observation that 2324 = 38 60 + 44 2324 = 38\cdot 60+44 .

Q E D \mathbb{QED}

Adit Mohan
Dec 26, 2013

write down the last digits of the first few fibonacci numbers. we can be sure that a repeating sequence will be found after 100 numbers because max no. of distinct ordered pairs (a,b) where ab are single digit =100.
the sequence repeats after 60th term (61st therm =1,62nd=1).
counting 3s firs 60have 8.
thus first 2280 have 8*38=304.
first 44 consist of 5 3s thus 2281to2324 also have 5 3s.
answer =304+5=309

Nafees Zakir
Sep 25, 2014

Why waste time and Ink of your pen when you've got Python. I simply wrote a code and Saved it as Fib2324.py and Ran it. The code is given below:

1
2
3
4
5
6
7
a, b = 1, 1
total = 0
for n in range(2324):
    if (a % 10)-3 == 0:
        total += 1
    a, b = b, a+b  # the real formula for Fibonacci sequence
print total

And thus you get your answer as output = 309

PradyGame Dev
Feb 24, 2014

In Python, a more readable approach than the one-liner. First, iterate through all the Fibonacci numbers and check if the last digit ends with 3. Here is the code:

a = 0 
b = 1
n = 0
print a
print b
for i in range(1,2325):
    c = a + b
    a = b 
    b = c
if(c % 10 == 3):
        n +=1

print n

The result is:

0
1
309

Therefore, answer is 309!

Israel Smith
Jan 1, 2014

Assuming g(0) = 0. Fibonacci auxiliar recurrence is cyclic each 60 times, in other hands, periodic each 60 times. I will use a auxiliar recurrence function for look patterns. For example: g(n) = f(n) mod 10,

g(7) = 13 mod 10 = 3. g(1) = 1, g(2) = 1, g(3) = 2 .... g(10) = 5 ... g(59) = . Finish cycle at g(59). g(60) = g(0) = 0 g(60) = g(0)

So, generalizing: g(n) = g(60 * 1+k) = g(60 * 2+k) = . . . = g(60*p+k).

k is cycle position of g(n) and p number of cycles.

The number of 3's in g(n) is 8 per cycle.

2324 mod 60 = 44. Then, g(2324) = g(60 38+44) -> 38 8 + number of 3's between 0 and 44. -> 38*8 + 5 = 309

William Zhang
Dec 26, 2013

Put this in python

 list=[]

 k=eval(input("fibonacci"))

 d=1

 a=1

 b=1

 c=a+b

 for i in range(k-2)

     c=a+b

     a=b

     b=c

     if c%10==3:

         list.append(d)

 e=list.count(d)

 print(e)
Omar Obeya
Dec 26, 2013

last digit of fib(n) = last digit of fib(n-1) + last digit (n-2) MOD 10 keep tracing the last digits and you'll find fib(61) =1 and fib(62) = 1 , this means a cycle will be repeated over and over again in the first 60 Fibonacci numbers there are 8 numbers has their last digit = 3, so in the first 2340 there will be 8*39 = 312 but we need to remove all solutions from fib(2324) till fib(2340) they are equivalent to solutions from fib(44) to fib(60) which equal 3 so answer = 312 - 3 = 309

Andres Saez
Dec 26, 2013

Note that F 58 9 m o d 10 F_{58} \equiv 9\mod{10} , F 59 1 m o d 10 F_{59} \equiv 1\mod{10} . Thus, modulo 10, the Fibonacci numbers are periodic with period 60. In the first 60 Fibonacci numbers, there are 8 which are congruent to 3 modulo 10. There are 38 such sets of 60 in the first 2324 Fibonacci numbers. Because 2324 44 m o d 60 2324 \equiv 44 \mod{60} , we must count the number of fibonacci numbers congruent to 3 modulo 10 in the first 44 (5). Hence, there are 38 8 + 5 = 309 38 \cdot 8 + 5 = \boxed{309} Fibonacci numbers congruent to 3 modulo 10 in the first 2324.

The Pisano period mod 10 π ( n ) \pi ( n) is 60 (with 8 3's in a period)and for the 44 left we have 5 more. 8*38 + 5 = 309

Bogdan Simeonov - 7 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...