Problem 5:Smallest multiple
标签:最大公约数、最小公倍数
原文:252025202520 is the smallest number that can be divided by each of the numbers from 111 to 101010 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 111 to 202020?
翻译:252025202520 是最小的能够被 111 到 101010 整除的正数。
最小的能够被 111 到 202020 整除的正数是多少?
题解:很显然是求最小公倍数。
最大公约数(greatest common divisorgreatest\ common \ divisorgreatest common divisor):gcd(a,b)=gcd(b,a%b)gcd(a,b)=gcd(b,a\%b)gcd(a,b)=gcd(b,a%b)
最小公倍数(least common multipleleast \ common \ multipleleast common multiple):lcm(a,b)=a∗b/gcd(a,b)lcm(a,b)=a*b/gcd(a,b)lcm(a,b)=a∗b/gcd(a,b)
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ll k = 1;
for (ll i = 1; i <= 20; i++) {
k = k * i / gcd(k, i);
}
cout << k << endl;
return 0;
}
“Project Euler exists to encourage, challenge, and develop the skills and enjoyment of anyone with an interest in the fascinating world of mathematics.”
“欧拉计划的存在,是为了每个对数学感兴趣的人,鼓励他们,挑战他们,并最终培养他们的能力与乐趣。”