给出一个数,求最小公倍数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
*/
public class Main {
public static boolean isZhishu(int n){
int sqrt = (int)Math.sqrt((double) n);
return IntStream.rangeClosed(2, sqrt).noneMatch(i -> n % i == 0);
}
private static Function<String,BigInteger> bigInteger = BigInteger::new;


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()){
int x=in.nextInt();
System.out.println(gongbeishu(x));
}
}
static BiFunction<BigInteger,BigInteger,BigInteger> multiply2_a=
(e, n)-> Stream.generate(()->e).limit(n.longValue()).reduce(bigInteger.apply("1"), getBigIntegerBinaryOperator());

private static BinaryOperator<BigInteger> getBigIntegerBinaryOperator() {
return (a, b)->bigInteger.apply(a.toString()).multiply(bigInteger.apply(b.toString()));
}

public static BigInteger gongbeishu(int n){
Map<Integer, Integer> objectObjectConcurrentHashMap = new HashMap<>();
IntStream.rangeClosed(2, n). forEach(
fang->{
IntStream.rangeClosed(2, n).filter(Main::isZhishu)
.filter(
e->multiply2_a.apply(bigInteger.apply(e+""),bigInteger.apply(fang+"")).compareTo(bigInteger.apply(n+""))==-1
)
.forEach(a->{
objectObjectConcurrentHashMap.put(a,fang);
})
;
}
);
return IntStream.rangeClosed(2, n).filter(Main::isZhishu).mapToObj(e->{
return multiply2_a.apply(bigInteger.apply(e+""),bigInteger.apply(Optional.ofNullable(objectObjectConcurrentHashMap.get(e)).orElse(1)+""));
})
.reduce(bigInteger.apply("1"), getBigIntegerBinaryOperator());

}
}