题意:
输入N,求至少两个数 使其lcm值为 N
#include<iostream>
#include<cmath>using namespace std;
typedef long long LL;
const LL INF = 0x7fffffff;
const int M = sqrt(INF + 0.5);
LL P[M];
int count;
void Get(LL n) {
count = 0;
const int m = sqrt(n + 0.5);
//static int P[m];
for(int i = 2; i <= m && n > 1; ++i) {
if(n % i == 0)
{
LL pos = 1;
while(n % i == 0)
n /= i, pos*= i;//把每个素数的值撸下来
P[count++] = pos;//本想用个辅助数组存指数,结果我傻逼,每个ai ^ n是不会超int的,所以直接存.
}
}
if(n > 1) P[count++] = n;
}
int main() {
int Case = 1;
LL n;
while(cin >> n && n) {
printf("Case %d: ",Case++);
LL ans = 0;\
Get(n);
for(int i = 0; i < count; ++i) ans += P[i];
if(count == 0 || count == 1)
ans = n + 1;
cout << ans << endl;
}
return 0;
}