Title Link: http://lightoj.com/volume_showproblem.php?problem=1024
Test instructions: Give you the number of n (2<=n<=1000), and then the number of n least common multiple, the size of each number is 1---10000, so the answer will be very large, may reach 1000 4-digit multiplication, so the result is very large, nearly 4,000 bits;
So it's going to involve high-precision operations, and we can't just cycle through the least common multiple; we can divide a number into multiple prime numbers, and then find the one that corresponds to the most prime numbers in each of them, and then multiply the results.
Example of a sample
4
5 6 30 60
5:5//Description There must be a factor in the least common multiple 5
6:2*3//Description The factor of least common multiple must have a 2 and a 3;
30:2*3*5//Description The factor of least common multiple must have a 2 and a 3 and a 5;
60:2^2*3*5//Description The least common multiple factor must have 2 2 and one 3 and one 5;
So we can ignore those numbers less, find out the results of the description must contain 2 2 a 3 a 5;
It is important to note that because each time a large integer is multiplied by n, so that the tle is not several times, so can be used to output a number of methods;
#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>typedefLong LongLL;#defineN 10001using namespacestd;Const DoubleEPS = 1e-6;intf[101], p[101], k =0;voidPrime () { for(intI=2; i<101; i++) { if(!f[i]) p[k++] =i; for(intJ=i; j<101; j+=i) f[j]=1; }}intans[1001], cnt[n];voidMul (intA[],intnum) { for(intI=0; i< +; i++) A[i]= a[i]*num; for(intI=0; i< +; i++) {A[i+1] + = a[i]/10000; A[i]= a[i]%10000; }}voidPUTS (inta[]) { intI= +; while(i>=0&& a[i]==0) i--; printf ("%d", a[i--]); while(i>=0) printf ("%04d", a[i--]); printf ("\ n");}intMain () {Prime (); intN, t, t =1; scanf ("%d", &T); while(t--) {memset (CNT,0,sizeof(CNT)); memset (ans,0,sizeof(ans)); intnum; scanf ("%d", &N); for(intI=1; i<=n; i++) {scanf ("%d", &num); for(intj=0; J<k && p[j]*p[j] <= num; J + +) { ints =0; while(Num%p[j] = =0) {s++; Num/=P[j]; } Cnt[p[j]]=Max (Cnt[p[j]], s); } if(Num >1) Cnt[num]= Max (Cnt[num],1); } ans[0] =1; for(intI=0; i<n; i++) { if(!cnt[i])Continue; intRET =1; for(intj=0; j<cnt[i]; J + +) ret*=i; Mul (ans, ret); } printf ("Case %d:", t++); PUTS (ANS); } return 0;}
View Code
Lightoj1024-eid (number of minimum conventions for n number + high precision)