(Problem 5)Smallest multiple
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> #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; }
Answer:
|
232792560 |
作者:acutus
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.