Project Euler #34: Digit factorials

  • + 0 comments

    JavaCode

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            int[] facts = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
            Scanner s = new Scanner(System.in);
            int N = s.nextInt();  
            int count = 0;
    
            for (int i = 10; i <= N; i++) {
                int number = i;
                int sum = 0;
    
                while (number != 0) {
                    int temp = number % 10;  
                    sum += facts[temp]; 
                    number /= 10;  
                }
    
                if (sum % i == 0) {
                    count+=i;
                }
            }
    
            System.out.println(count);
        }
    }