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?
最小倍数
2520是最小的能够被1到10整除的数。
最小的能够被1到20整除的正数是多少?
代码演示
#include<iostream>
using namespace std;
typedef long long lint;;
lint gcd(lint a,lint b){
return (b? gcd(b,a%b):a);
}
int main(){
lint ans=1;
for(int i=2;i<=20;i++){
ans=ans*i/gcd(ans,i);
}
cout<<ans<<endl;
return 0;
}
答案
232792560