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)