本文章来自我的个人网站,如感兴趣,欢迎访问我的个人网站:http://www.qingshuimonk.com/
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?
其实也没什么难的,1~20的最小公倍数。首先,把互质的几个数——3,5,7,11,13,17,19相乘,得到4849845,易证得该最小公约数一定是4849845的倍数。然后用遍历法,判断其是否能被1~20整除,3、5、7、11、13、17、19不用验证,2、4、5、6、7、8、9由于20、18、16、15、14、12、10的存在不用验证。所以只用验证剩下的就可以了。
程序:
void main()
{
long i;
for(i = 4849845;; i = i+4849845)
{
if(i%20 == 0)
if(i%18 == 0)
if(i%16 == 0)
if(i%15 == 0)
if(i%14 == 0)
if(i%12 == 0)
if(i%10 ==0)break;
}
printf("%d\n",i);
}