题目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.
时间: 2024-12-30 04:07:50