Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101162

Re: Trailing zeros of 100!

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Trailing zeros of 100!
Date Sat, 02 Jan 2016 18:18:05 +0100
Organization None
Lines 37
Message-ID <mailman.173.1451755097.11925.python-list@python.org> (permalink)
References <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> <n68rrg$k29$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de Yve7DynSqo0HM6rjaCRadQADTG6G++XVM5PhxqURi4Lw==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'trailing': 0.07; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'zeros': 0.09; 'python': 0.10; 'def': 0.13; '"0"': 0.16; 'failed.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'skip:2 150': 0.16; 'wrote:': 0.16; 'module,': 0.18; '>>>': 0.20; 'math': 0.20; 'trying': 0.22; 'help.': 0.23; 'represents': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:t 40': 0.27; 'least': 0.27; 'factor': 0.29; "i'm": 0.30; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'end': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'total': 0.62; 'more': 0.63; 'therefore': 0.67; 'factors': 0.97
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd9f57.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:101162

Show key headers only | View raw


Robin Koch wrote:

> Am 02.01.2016 um 12:49 schrieb katye2007@gmail.com:
> 
>> I'm trying to write a python program to find how many trailing zeros
>> are in 100! (factorial of 100). I used factorial from the math
>> module, but my efforts to continue failed. Please help.
> 
> Using not Python, but math:
> 
> Every "0" at the end of 100! represents a multiplication by the factor
> 10 or the factors 2 and 5.
> 
> There are 20 numbers with at least one factor 5.
> There are  4 numbers with at least two factors 5 (=25).
> There are no numbers with three factors 5 (=125).
> 
> There are 50 numbers with at least one factor 2.
> 
> So 100! contains 24 factors 5 and even more factors 2.
> So 100! contains 24 facotrs 10 and therefore has 24 trailing zeros.

Spelt in Python:

>>> def trailing_zeros_fact(n):
...     total = 0
...     while n:
...         n //= 5
...         total += n
...     return total
... 
>>> trailing_zeros_fact(100)
24
>>> trailing_zeros_fact(math.factorial(100))
23331553860986038170424809714066675122678992066095405367148240973804399998307478902235365994039129571563424480206805939562796302729215999999999999999999999901

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Trailing zeros of 100! katye2007@gmail.com - 2016-01-02 03:49 -0800
  Re: Trailing zeros of 100! David <bouncingcats@gmail.com> - 2016-01-02 23:19 +1100
  Re: Trailing zeros of 100! katye2007@gmail.com - 2016-01-02 04:34 -0800
  Re: Trailing zeros of 100! Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-02 13:44 +0100
  Re: Trailing zeros of 100! "yehudak ." <katye2007@gmail.com> - 2016-01-02 15:14 +0200
    Re: Trailing zeros of 100! Robin Koch <robin.koch@t-online.de> - 2016-01-02 16:57 +0100
      Re: Trailing zeros of 100! Tony van der Hoff <tony@vanderhoff.org> - 2016-01-02 17:09 +0100
        Re: Trailing zeros of 100! Robin Koch <robin.koch@t-online.de> - 2016-01-02 17:56 +0100
          Re: Trailing zeros of 100! Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-02 15:24 -0200
          Re: Trailing zeros of 100! Chris Angelico <rosuav@gmail.com> - 2016-01-03 08:57 +1100
            Re: Trailing zeros of 100! Robin Koch <robin.koch@t-online.de> - 2016-01-03 01:02 +0100
              Re: Trailing zeros of 100! Ben Finney <ben+python@benfinney.id.au> - 2016-01-03 11:20 +1100
              Re: Trailing zeros of 100! srinivas devaki <mr.eightnoteight@gmail.com> - 2016-01-03 07:16 +0530
          Re: Trailing zeros of 100! Tony van der Hoff <tony@vanderhoff.org> - 2016-01-03 11:53 +0100
  Re: Trailing zeros of 100! Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-02 09:57 -0500
  Re: Trailing zeros of 100! Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-02 16:24 +0100
  Re: Trailing zeros of 100! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-01-02 15:30 +0000
  Re: Trailing zeros of 100! Robin Koch <robin.koch@t-online.de> - 2016-01-02 16:54 +0100
    Re: Trailing zeros of 100! Peter Otten <__peter__@web.de> - 2016-01-02 18:18 +0100
  Re: Trailing zeros of 100! Tim Chase <python.list@tim.thechases.com> - 2016-01-02 10:33 -0600
  Re: Trailing zeros of 100! "yehudak ." <katye2007@gmail.com> - 2016-01-02 19:34 +0200
  Re: Trailing zeros of 100! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-01-02 17:44 +0000
    Re: Trailing zeros of 100! Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-03 00:36 +0100
  Re: Trailing zeros of 100! Serhiy Storchaka <storchaka@gmail.com> - 2016-01-02 20:28 +0200
  Re: Trailing zeros of 100! Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-01-02 19:29 +0100
  Re: Trailing zeros of 100! "yehudak ." <katye2007@gmail.com> - 2016-01-02 22:02 +0200
  Re: Trailing zeros of 100! "yehudak ." <katye2007@gmail.com> - 2016-01-02 22:09 +0200
  Re: Trailing zeros of 100! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-01-02 21:25 +0000
  Re: Trailing zeros of 100! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-01-02 21:26 +0000

csiph-web