uva10791 (decomposition factorization)

Source: Internet
Author: User

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 1732

Given us a n, to find a set of two numbers, so that these books least common multiple (LCM) is n, because there are many such sets, we want to select the sum of the smallest, but also as long as the output sum of the line

What is the maximum common multiple of a number? is multiplied by the largest of each factorization index.

By least common multiple, we can see that least common multiple depends on the highest number of each mass factor in each of the numbers.

If we want the sum to be the smallest, we have to put the same mass factor into an integer.

Because A*b>a+b

For example, 3 * 2^2 a = 3, b = 2 A * b > a + b i.e. 2*3 > 2 + 3

So the final result is 3 * 4 = 12, at this time and minimum, 7

1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <algorithm>5#include <iostream>6#include <queue>7#include <stack>8#include <vector>9#include <map>Ten#include <Set> One#include <string> A#include <math.h> - using namespacestd; - #pragmaWarning (disable:4996) thetypedefLong LongLL;  - Const intINF =1<< -; - /* -  + */ - intMain () + { ALL N, I, m, k =1; at LL ans; -      while(SCANF ("%lld", &N), N) -     { -         intnn =N; -Ans =0; -m = sqrt (n) +0.5; in         intCNT =0; -          for(i =2; I <= m; ++i) to         { +             if(n%i = =0) -             { the                 intt =1; *                  while(n%i = =0) $                 {Panax NotoginsengT *=i; -N/=i; the                 } +Ans + =T; Acnt++; the             } +         } -         if(N >1) $         { $Ans + =N; -cnt++; -         } the         if(CNT = =1)//This is only a single number of cases -Ans + =1;Wuyi         Else if(CNT = =0)//This is a condition where n is 1. theAns + =2; -printf"Case %lld:%lld\n", k++, ans); Wu     } -     return 0; About}
View Code

uva10791 (decomposition factorization)

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.