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 |
相关推荐
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input...
ACM试题Problem K:Ones ...= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1 s. How many digits are in the smallest such a multiple of n?
### 问题5:Smallest multiple **问题描述**: 找出所有1到20的正整数的最小公倍数。 **解决方案**: 可以通过分解每个数的质因数,然后取每个质因数的最大幂次作为最小公倍数。 ```javascript function lcm...
5. Wifi (802.11): home and enterprise: 6. 3G and 4G: wide-area wireless. HFC bandwidth is shared among the users. On the downstream channel, all packets emanate from a single source, namely, the ...
- **Sorting by Straight Selection**: Selects the smallest (or largest) element and moves it to its final position. - **Sorting by Straight Exchange**: Exchanges adjacent elements if they are out of ...
# [LeetCode](https://leetcode.com/problemset/algorithms/)  [![License]...
- ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now ...