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.io.*;importjava.util.*;publicclassSolution{/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */staticbooleanisPandigital(intn,intk){inti=1;StringBuildernumbers=newStringBuilder();while(true){numbers.append(n*i);if(numbers.length()>=k){break;}i++;}if(numbers.length()==k&&isSubset(numbers.toString(),k)){returntrue;}returnfalse;}staticbooleanisSubset(Stringnumbers,intk){for(inta=1;a<=k;a++){if(!numbers.contains(Integer.toString(a))){returnfalse;}}returntrue;}publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);String[]input=scanner.nextLine().split(" ");intn=Integer.parseInt(input[0]);intk=Integer.parseInt(input[1]);for(inti=2;i<n;i++){if(isPandigital(i,k)){System.out.println(i);}}scanner.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #38: Pandigital multiples
You are viewing a single comment's thread. Return to all comments →
JAva code