We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.Scanner;publicclassSolution{publicstaticintf(intnum){intfact=num;if(num==0){fact=1;}else{for(inti=num-1;i>0;--i){fact=fact*i;}}returnfact;}publicstaticintfn(intn){intsum_f=0;Stringtemp=String.valueOf(n);for(inti=0;i<temp.length();++i){intconv_i=temp.charAt(i)-'0';sum_f+=f(conv_i);}returnsum_f;}publicstaticintsfn(intnum){intsum_fn=0;intsum_f=fn(num);Stringtemp=String.valueOf(sum_f);for(inti=0;i<temp.length();++i){intconv_i=temp.charAt(i)-'0';sum_fn+=conv_i;}returnsum_fn;}publicstaticintgi(intnum){intsum_fn;inti=0;while(true){++i;sum_fn=sfn(i);if(num==sum_fn){break;}}returni;}publicstaticintsgi(intnum){intsum_gi=0;for(inti=1;i<=num;++i){inttemp=gi(i);if(temp<10){sum_gi+=temp;}else{Strings_temp=String.valueOf(temp);for(intj=0;j<s_temp.length();++j){intconv_i=s_temp.charAt(j)-'0';sum_gi+=conv_i;}}}returnsum_gi;}publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intq=scanner.nextInt();for(inti=0;i<q;++i){intn=scanner.nextInt();intm=scanner.nextInt();// not used in the codeSystem.out.println(sgi(n));}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #254: Sums of Digit Factorials
You are viewing a single comment's thread. Return to all comments →
IN JAVA BY: TANUSHREE SARKAR