【题目】
【答案】本题答案为232792560。
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
【翻译】
2520是最小的能被1-10中每个数字整除的正整数。
最小的能被1-20中每个数整除的正整数是多少?
【思路】将每个数质因子分解,之后求最小公倍数。【代码】
bool isPrime( int value)
{
if(value==2)
return true;
if(value<2 || (!(value&1)))
return false;
for(int i=2;i<(int)sqrt(value)+1;i++)
{
if(value%i==0)
{
return false;
}
}
return true;
}
void test5()
{
const int N=20;
//构造素数表
int Primer[N]={0};
for(int i=0;i<N;i++)
{
if(isPrime(i))
Primer[i]=1;
}
//删掉重复的质因子
int s;
int end=(int) sqrt(N);
for(int j=0;j<end+1;j++)
{
if(Primer[j])
{
s=j;
while(s<N)
s*=j;
s/=j;
Primer[s]=1;
Primer[j]=0;
}
}
//输出结果
long long int answer=1;
for(int i=0;i<N;i++)
{
if(Primer[i])
answer*=i;
}
cout<<answer<<endl;
}
//跑出上述结果后,可以直接予以输出
<pre name="code" class="cpp">/*void test5()
{
long int answer=9*16*5*7*11*13*17*19;
cout<<answer<<endl;
}*/
【答案】本题答案为232792560。