# SPOJ 11. factorial use python

Page 1 of 1

## 3 Replies - 644 Views - Last Post: 18 February 2013 - 05:17 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312587&amp;s=950993c74e01c221ff37484df6d08358&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sillygod

Reputation: 0
• Posts: 14
• Joined: 23-January 13

# SPOJ 11. factorial use python

Posted 18 February 2013 - 02:39 AM

here is the question

```numTest = int(input())
result = ''
for i in range(numTest):
N = int(input())
N_Z = 0
while N > 0:
N //=5
N_Z+=N
result+= '{}\n'.format(N_Z)

print(result)

```

I use this way to solve this problem but I get a TLE. after thinking and thinking, I can't think any better way to solve this. Did anyone has any better idea?

Is This A Good Question/Topic? 0

## Replies To: SPOJ 11. factorial use python

### #2 andrewsw

• I'm not here to twist your niblets

Reputation: 4106
• Posts: 14,830
• Joined: 12-December 12

## Re: SPOJ 11. factorial use python

Posted 18 February 2013 - 03:37 AM

What is a TLE? In fact, what is a SPOJ 11?

This post has been edited by andrewsw: 18 February 2013 - 03:38 AM

### #3 sepp2k

• D.I.C Lover

Reputation: 2180
• Posts: 3,368
• Joined: 21-June 11

## Re: SPOJ 11. factorial use python

Posted 18 February 2013 - 03:40 AM

sillygod, on 18 February 2013 - 10:39 AM, said:

Did anyone has any better idea?

Try printing the results as soon as you have them instead of building up a string. If there are many test cases, I can see that making a noticeable performance difference. The algorithm itself looks like it should have an acceptable runtime to me.

andrewsw, on 18 February 2013 - 11:37 AM, said:

What is a TLE?

Time limit exceeded.

### #4 sillygod

Reputation: 0
• Posts: 14
• Joined: 23-January 13

## Re: SPOJ 11. factorial use python

Posted 18 February 2013 - 05:17 AM

sepp2k, on 18 February 2013 - 03:40 AM, said:

sillygod, on 18 February 2013 - 10:39 AM, said:

Did anyone has any better idea?

Try printing the results as soon as you have them instead of building up a string. If there are many test cases, I can see that making a noticeable performance difference. The algorithm itself looks like it should have an acceptable runtime to me.

andrewsw, on 18 February 2013 - 11:37 AM, said:

What is a TLE?

Time limit exceeded.

Hello, sepp2k

Thanks for your reply. I also try to print immediately but it's still the same.
this algorithm will be accepted if you use C or C++. However, in python, I got a TLE

Regards,
sillygod

andrewsw, on 18 February 2013 - 03:37 AM, said:

What is a TLE? In fact, what is a SPOJ 11?