LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is amultiple of all integers of that set. It is interesting to note that any positive integer can be expressedas the LCM of a set of positive integers. For example 12 can be expressed as the LCM of 1, 12 or12, 12 or 3, 4 or 4, 6 or 1, 2, 3, 4 etc.In this problem, you will be given a positive integerN. You have to find out a set of at least two positive integerswhose LCM is N. As infinite such sequences arepossible, you have to pick the sequence whose summationof elements is minimum. We will be quite happyif you just print the summation of the elements of thisset. So, for N = 12, you should print 4+3 = 7 asLCM of 4 and 3 is 12 and 7 is the minimum possiblesummation.
Input
The input file contains at most 100 test cases. Eachtest case consists of a positive integer N (1 ≤ N ≤231 − 1).Input is terminated by a case where N = 0. Thiscase should not be processed. There can be at most100 test cases.
Output
Output of each test case should consist of a line starting with ‘Case #: ’ where # is the test casenumber. It should be followed by the summation as specified in the problem statement. Look at theoutput for sample input for details.
Sample Input
12
10
5
0
Sample Output
Case 1: 7
Case 2: 7
Case 3: 6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
数论+思路~
对于n,几个互质的数的和一定是最小的,所以直接分解质因数求和就可以了~
要注意的是n==1或者n为质数的时候,要输出n+1~
#include<cstdio>
#define ll long long
int cnt;
ll n,tot;
int main()
{
while(scanf("%lld",&n)==1 && n)
{
printf("Case %lld: ",++cnt);tot=0;
if(n==1)
{
printf("2\n");continue;
}
int kkz=n;
for(ll i=2;i*i<=n;i++)
if(!(n%i))
{
ll now=1;
while(!(n%i)) now*=i,n/=i;
tot+=now;
}
if(n>1) tot+=n;
if(tot==kkz) tot++;
printf("%lld\n",tot);
}
return 0;
}