You are viewing a single comment's thread. Return to all comments →
I don't know if my code is the most efficient way, but it solved all testcases.
import java.util.Scanner; public class Peuler34 { public static void main(String[] args) { int n,temp; Scanner sc = new Scanner(System.in); n = sc.nextInt(); int count=0; int sum=0; for(int i=10;i<=n;i++){ temp = i; while(temp>0){ sum+= fact(temp%10); temp = temp/10; } if(sum%i==0) count+=i; sum=0; } System.out.println(count); } static int fact(int n){ int res=1; if(n==0) return 1; for(int i=1;i<=n;i++){ res*=i; } return res; } }
Project Euler #34: Digit factorials
You are viewing a single comment's thread. Return to all comments →
I don't know if my code is the most efficient way, but it solved all testcases.