Ultraviolet-10791-Minimum Sum LCM (number theory related !)

Source: Internet
Author: User

Ultraviolet-10791-Minimum Sum LCM (number theory related !)

Link: Minimum Sum LCM


UV-10791

Minimum Sum LCM
Time Limit:3000 MS Memory Limit:Unknown 64bit IO Format:% Lld & % llu

SubmitStatus

Description


Minimum Sum LCM

LCM(Least Common Multiple) of a set of integers is defined as the minimum number, which is a multiple of all integers of that set. it is interesting to note that any positive integer can be expressed asLCMOf a set of positive integers. For example12Can be expressed asLCMOf1,12Or12,12Or3,4Or4,6Or1,2,3,4Etc.

In this problem, you will be given a positive integerN. You have to find out a set of at least two positive integers whoseLCMIsN. As infinite such sequences are possible, you have to pick the sequence whose summation of elements is minimum. we will be quite happy if you just print the summation of the elements of this set. so,N= 12, you shoshould print4 + 3 = 7AsLCMOf4And3Is12And7Is the minimum possible summation.

Input

The input file contains at most100Test cases. Each test case consists of a positive integerN(1N231-1 ).

Input is terminated by a case whereN= 0. This case shocould not be processed. There can be at most100Test cases.

Output

Output of each test case shoshould consist of a line starting'Case #:'Where # is the test case number. It shocould be followed by the summation as specified in the problem statement. Look at the output for sample input for details.

Sample Input
 121050
Sample Output
 Case 1: 7Case 2: 7Case 3: 6


Problem setter: Md. Kamruzzaman
Special Thanks: Shahriar ManzoorMiguel Revilla 2004-12-10

Source

Root: aoapc ii: Beginning Algorithm Contests (Second Edition) (Rujia Liu): Chapter 10. Maths: Examples
Root: aoapc I: Beginning Algorithm Contests (Rujia Liu): Volume 6. Mathematical Concepts and Methods
Root: aoapc I: Beginning Algorithm Contests -- Training Guide (Rujia Liu): Chapter 2. Mathematics: Basic Problems
Root: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim): Mathematics: Number Theory: Working with Prime Factors

Root: Prominent Problemsetters: Md. Kamruzzaman (KZaman)
Root: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim): Mathematics: Number Theory: Working with Prime Factors


Idea: break down the prime factor, break down the prime factor with the smallest public factor, and the smallest ans will be the sum of the corresponding power numbers of each prime factor.

This question is difficult:

1. When N = 1, 2 should be output;

2. When N is a prime number, N + 1 is output;

3. When only the element factor is used, sum = the power of the prime factor + 1;

4. When N = 2147483647, It is a prime number. At this time, the output is 2147483648, But it exceeds the int range. We should consider using long.



AC code:

/*************************************** * *********************************> File Name: e. cpp> Author: zzuspy> Mail: zzuspy@qq.com> Created Time: monday, December 01, 2014, 33 seconds ******************************** **************************************** /# include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Define LL long # define max3 (a, B, c) max (a, max (B, c) # define min3 (a, B, c) min (, min (B, c) using namespace std; int main () {int n, cas = 1; while (scanf ("% d", & n), n) {int m = (int) sqrt (double) n + 0.5); int t = n, num = 0; LL ans = 0; for (int I = 2; I <= m; I ++) // break down this number if (t % I = 0) {num ++; // record the number of quality factors int tmp = 1; while (t % I = 0) {tmp * = I; t/= I;} ans + = tmp;} if (n = t) // when it is a prime number, ans = (LL) n + 1; // A (LL) else if (num = 1 | t! = 1) // single element factor, or ans + = t when there is a qualitative factor greater than sqrt (n); // In the case of single element factor, t is 1, when the remaining one is greater than sqrt (n) prime factor, t is the residual prime factor printf ("Case % d: % lld \ n", cas ++, ans);} return 0 ;}
       
      
     
    
   
  
 






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.