码迷,mamicode.com
首页 > 其他好文 > 详细

欧拉计划·第五题

时间:2015-03-17 20:16:00      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:欧拉计划

题目5:找出最小的能被1-20中每个数整除的数。

2520是最小的能被1-10中每个数字整除的正整数。

最小的能被1-20中每个数整除的正整数是多少?

源码

STDMETHODIMP COuLa::Test5(int number)
{
	// TODO: 在此添加实现代码
	int iForNumber[MAX_PATH] = {0};
	int iForFinalNumber[MAX_PATH] = {0};

	for(int i = number; i>0; i--)
	{
		int c = i;
		int j = c;
back_to_add:
		for( j = 2;j<=i;j++)
		{
			if(c%j == 0)
			{
				c = c/j;
				iForNumber[j]++;
				goto back_to_add;
			}
		}
		iForNumber[c]++;

		for(int y = 0; y<=number; y++)
		{
			if(iForNumber[y] > iForFinalNumber[y] )
			{
				iForFinalNumber[y] = iForNumber[y];
			}
			iForNumber[y] = 0;
		}
	}
	__int64 result = 1;
	for(int i = 0; i<=number; i++)
	{
		while(iForFinalNumber[i]>0)
		{
			result = result*i;
			iForFinalNumber[i]--;
		}
	}
	printf("The Test 5 Number is %d.\n",result);
	return S_OK;
}


函数调用
#define TEST5_NUMBER 20
IOula->Test5(TEST5_NUMBER);

输出

The Test 5 Number is 232792560.



欧拉计划·第五题

标签:欧拉计划

原文地址:http://blog.csdn.net/u010095741/article/details/44346511

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!