首页 > 其他 > 详细

(Problem 5)Smallest multiple

时间:2014-02-11 19:47:03      阅读:376      评论:0      收藏:0      [点我收藏+]

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?

bubuko.com,布布扣
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
  
#define N 20
  
int gcd(int a, int b)
{
  if(b==0)
    return a;
  else
    return gcd(b,a%b);
}
  
int lcm(int a, int b)
{
  return a/(gcd(a,b))*b;
}
  
  
void solve()
{
   int i,s=2;
   for(i=3; i<=N; i++)
   {
      s=lcm(s,i);
   }
   printf("%d\n",s);
}
  
int main()
{
  solve();
  return 0;
}
bubuko.com,布布扣
Answer:
232792560

(Problem 5)Smallest multiple

原文:http://www.cnblogs.com/acutus/p/3544407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!