# 求一列数的最小公倍数

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之间的每个数字整除的最小整数。

```void swith_param_order(int *a, int *b)
{
int tmp;
if(a<b)
{
tmp=a;
a=b;
b=tmp;
}
}

int max_common_divisor(int a, int b)
{
int r;
int divisor;
swith_param_order(&a,&b);
r=a%b;
if(r==0)
{
divisor=b;
}
else
{
divisor=max_common_divisor(b,r);
}
return divisor;
}

int smallest_multiple(int num)
{
int i;
int result=1;
for(i=1;i<=num;i++)
{
if(result%i==0)
{
continue;
}
else
{
//calculate the smallest multiple of result and i
result=(result*i)/max_common_divisor(result,i);
}
}
return result;
}

void TestSmallestMultiple()
{
int num=20;
printf("Smallest Multiple:%d\\n",smallest_multiple(num));
}
//该片段来自于http://outofmemory.cn
```

0人收藏

0

0

»更多 您可能感兴趣的代码
1. 2014-12-06 11:00:26词法分析 by 童学芬
2. 2012-11-03 19:21:55c语言实现顺序查找和二分查找的示例 by 林峰
3. 2012-12-06 21:23:15c++大数阶乘算法 by zetaliang
4. 2012-12-20 13:30:20伪造硬币问题 by 傅小黑
5. 2013-07-27 15:09:08C++顺序表操作代码演示 by qqmmcc
6. 2014-04-05 14:40:50C++算法之可变参数 by 童学芬
7. 2014-05-18 11:40:55KMP字符串匹配算法 by 童学芬
8. 2014-05-19 15:46:15高效素数筛法 by lucasli
9. 2014-05-20 12:48:01线性表之顺序表 by 千万不要郁闷
10. 2014-05-22 13:29:39递归题改为非递归题实例 by lucasli
11. 2014-05-27 11:43:40广度优先遍历 by aiheng1988

1. dianlujitao 发表 2014-10-17 13:45:25 POJ 3122 Pie
2. bystander 发表 2013-04-16 00:42:58 模板优先级队列及堆排序(C++实现)
3. dianlujitao 发表 2014-10-17 13:52:22 POJ 2388 Who’s in the Middle
4. surgesoft 发表 2014-10-28 08:01:58 LeetCode OJ: Restore IP Addresses
5. espace 发表 2015-07-18 17:43:14 Two Sum
6. abyssss 发表 2014-05-20 03:23:39 数据结构 最小堆 数组实现
7. dianlujitao 发表 2014-10-17 13:56:48 POJ 1611 The Suspects
8. bystander 发表 2013-05-15 10:37:24 倒水问题求解(C++)
9. dianlujitao 发表 2014-10-17 14:11:26 POJ 1328 Radar Installation
10. bystander 发表 2013-04-01 10:12:37 [藏]关于B树的一篇文章
11. lvfuyu 发表 2015-04-12 08:53:30 [hihocoder]矩阵快速幂
12. lvfuyu 发表 2015-04-18 09:13:32 [hihocoder]二分查找