SPOJ same algorithm adopted in C, Time limit Exceeded in Python

I am trying to solve the FCTRL problem from SPOJ. The problem is to find the number of trailing zeros in N! for some T-tests.

T ~ 1,00,000.
1 <= N <= 1000000000

My problem is very strange. If I try the following C code, it will be accepted with a time of 0.22 seconds and a memory capacity of 1.6 M. But if I send equivalent Python 3 code, it says that the time limit exceeded 11M memory usage.

C code:

#include <stdio.h>

void fact_zeros(long int);

int main(void) {
    long int i,t,n;
    if (scanf("%ld",&t) > 0) {
        for (i=1;i<=t;i++) {
            if (scanf("%ld",&n) > 0) {
                fact_zeros(n);
            }
        }
    }
    return 0;
}

void fact_zeros(long int N) {
    long int zeros = 0;
    while (N>0) {
        N = N / 5;
        zeros += N;
    }
    printf("%ld\n",zeros);
}

Python 3 code:

"""
spoj11Factorial.py
This program calculates the number of zeroes at the 
end of the factorial of each number of the test case.
"""

def fact_zeroes( n ):
    count_5s = 0
    while (n > 0):
        n = n // 5
        count_5s += n
    return count_5s


T = int( input() )
while (T):
  T -= 1
  n = int( input() )
  zeroes = fact_zeroes( n )
  print( zeroes )

Can anyone point out what I / what I am doing in Python code. It works for all given test cases on my machine.

Thank.

EDIT: Specifications of the problem:

Added by:   Adrian Kosowski
Date:   2004-05-09
Time limit: 6s
Source limit:   50000B
Memory limit:   256MB
Cluster:    Pyramid (Intel Pentium III 733 MHz)
Languages:  All except: NODEJS PERL 6
Resource:   ACM Central European Programming Contest, Prague 2000
+3
source share
1 answer

- :

n = int( input() )

n = int( raw_input() )

, raw_input() , input() Python .

Python 2.7 1,6 0,7

+5

All Articles