# SPOJ 11. factorial use python

Page 1 of 1

## 3 Replies - 867 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=60d7dad3cd9b4188fc1f399d81b64345&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sillygod

• New D.I.C Head

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

• But the opposite, you said.

Reputation: 5527
• Posts: 21,812
• 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: 2307
• Posts: 3,570
• 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

• New D.I.C Head

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?

I think I have give a link about the question.
SPOJ is the name of site.
11 means the quesiton number.

maybe, the link is not clear. I'm sorry about that.

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}