You are viewing a single comment's thread. Return to all comments →
My java Solution :
import java.util.Scanner; import java.util.function.Function; import java.util.stream.Stream; public class Solution { public static void main(String[] args) { Function<String, Integer> digitSum = x -> Stream.of(x.split("")) .mapToInt(Integer::parseInt) .sum(); Function<Integer, String> primeFactorSum = x -> { StringBuilder sum = new StringBuilder(); for (int i = 2; i < x; i++) { while (x % i == 0) { sum.append(i); x = x / i; } } if (x > 2) sum.append(x); return sum.toString(); }; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n == 1) { System.out.println(0); return; } Integer ds = digitSum.apply(String.valueOf(n)); Integer pfs = digitSum.apply(primeFactorSum.apply(n)); System.out.println(ds.equals(pfs) ? 1 : 0); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Identify Smith Numbers
You are viewing a single comment's thread. Return to all comments →
My java Solution :