zetn:参考你的代码进行修改: #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
int c = a%b;
if(c)
return gcd(b, c);
else
return b;
}
int lcm(int a, int b){
return a*b / gcd(a,b);
}
int main(){
int n, m = 0;
int q = 1, p, r, s;
while(cin >> n){
for(int i = 1; i <= n; i++){
q = lcm(i, q);
}
for(int m = n+1; ; m++){
p = n + 1;
int ok = 0;
for(int k = n+1; k <= m; k++){
p = lcm(p, k);
q = lcm(q, k);
if(p == q){
ok = 1;
cout << m << endl;
break;
}
}
if(ok)
break;
}
}
return 0;
}
投递腾讯等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了: