Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DroppingNumbers
- {
- public static void main(String[] args)
- {
- loop:
- for (long i=12; i<=987654321L; i++)
- {
- String s=""+i;
- int[] count=new int[10];
- for (int k=0; k<s.length(); k++)
- {
- int d=(int)(s.charAt(k)-'0'); //dropped digit
- if (d==0) continue loop; //cannot have digit 0
- count[d]++;
- if (count[d]==2) continue loop; //cannot have repeated digits
- String s2=s.substring(0,k)+s.substring(k+1);
- if (Long.parseLong(s2)%d!=0) continue loop; //truncated number does not divide by d
- }
- System.out.println(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement