Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
怎么才能减少时间啊?500ms我的算法很简单,就是计算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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator