3 Replies - 484 Views - Last Post: 18 February 2013 - 05:17 AM Rate Topic: -----

#1 sillygod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3222
  • View blog
  • Posts: 10,810
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

Re: SPOJ 11. factorial use python

Posted 18 February 2013 - 03:40 AM

View Postsillygod, 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.

View Postandrewsw, on 18 February 2013 - 11:37 AM, said:

What is a TLE?


Time limit exceeded.
Was This Post Helpful? 0
  • +
  • -

#4 sillygod  Icon User is offline

  • New D.I.C Head

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

Re: SPOJ 11. factorial use python

Posted 18 February 2013 - 05:17 AM

View Postsepp2k, on 18 February 2013 - 03:40 AM, said:

View Postsillygod, 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.

View Postandrewsw, 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

View Postandrewsw, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1