Problem
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?
- #include <stdio.h>
-
-
#define NUM 20
-
-
int main(int argc, const char *argv[])
-
{
-
int num[NUM];
-
int i, j;
-
int result = 1;
-
-
num[0] = 1;
-
for (i = 1; i < NUM; i++) {
-
num[i] = i;
-
for (j = 1; j < i; j++) {
-
if (!(num[i] % num[j]))
-
num[i] /= num[j];
-
}
-
}
-
-
for (i = 0; i < NUM; i++)
-
result *= num[i];
-
-
printf("result: %d\n", result);
-
-
return 0;
-
}
很巧妙的办法,但怎么用数学的***明是正确的呢?
阅读(1233) | 评论(0) | 转发(0) |