现在的位置: 首页 > 综合 > 正文

HDU-1124(数学技巧)

2013年11月09日 ⁄ 综合 ⁄ 共 634字 ⁄ 字号 评论关闭

看来前面的思路还是对的,就是说,其实判断0的个数就是判断2和5的个数,,,而2和5的最小的个数取决于零的个数.

但是,开始的时候不知道有那么个规律 就是说,质因数分解的时候,前面的幂次必定小于后面的幂次.

所以超时了,,呵呵.

贴出代码,下面的是超时的哦...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int N;
		int sum=0;
		scanf("%d",&N);
		while(N)
		{
			sum+=N/5;
			N/=5;
		}
		printf("%d\n",sum);
	}
	return 0;
}














/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>


int min(int a,int b)
{
	return a>=b?b:a;
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int N;
		scanf("%d",&N);
		int cnt1=0;
		int cnt2=0;
		for(int i=N;i>=2;i--)
		{
			int t=i;
			while(t%2==0)
			{
				cnt1++;
				t/=2;
			}
			t=i;
			while(t%5==0)
			{
				cnt2++;
				t/=5;
			}
		}
		printf("%d\n",min(cnt1,cnt2));
	}
	return 0;
}*/

 

【上篇】
【下篇】

抱歉!评论已关闭.