Chinaunix首页 | 论坛 | 博客
  • 博客访问: 238991
  • 博文数量: 47
  • 博客积分: 1229
  • 博客等级: 中尉
  • 技术积分: 568
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-20 10:06
文章分类

全部博文(47)

文章存档

2014年(1)

2013年(7)

2012年(1)

2011年(38)

分类: C/C++

2011-03-02 23:27:36


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?


  1. #include <stdio.h>

  2. #define NUM 20

  3. int main(int argc, const char *argv[])
  4. {
  5.     int num[NUM];
  6.     int i, j;
  7.     int result = 1;

  8.     num[0] = 1;
  9.     for (i = 1; i < NUM; i++) {
  10.         num[i] = i;
  11.         for (j = 1; j < i; j++) {
  12.             if (!(num[i] % num[j]))
  13.                 num[i] /= num[j];
  14.         }
  15.     }

  16.     for (i = 0; i < NUM; i++)
  17.         result *= num[i];
  18.     
  19.     printf("result: %d\n", result);

  20.     return 0;
  21. }
很巧妙的办法,但怎么用数学的***明是正确的呢?
阅读(1179) | 评论(0) | 转发(0) |
0

上一篇:euler3

下一篇:euler7

给主人留下些什么吧!~~