Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎么才能减少时间啊?500ms

Posted by xcl119xcl at 2007-07-27 11:36:55 on Problem 1401
我的算法很简单,就是计算n内有多少数是5的倍数,并且每个数能除几个5。
比如10,10/5=2;所以只有一个5,25/5=5,5/5=1,所以25有两个5 ,也就是说所有5的倍数,能分解为几个5
我的代码如下,怎么需要运行那么久呢????
#include <iostream>
using namespace std;
int main()
{
	int line,num;
	cin>>line;
	while(line>0)
	{
		line--;
		cin>>num;
		if(num<5)
			cout<<"0"<<endl;
		else
		{
			int b=0;	
			while(num>5)
			{
				b+=num/5;
				num=num/5;
			}
			cout<<b<<endl;
					
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator