Skip to content

Instantly share code, notes, and snippets.

@balamark
Created July 18, 2016 00:09
Show Gist options
  • Save balamark/8a7740e1d4f9fb0dc5cfe07b7c8b919c to your computer and use it in GitHub Desktop.
Save balamark/8a7740e1d4f9fb0dc5cfe07b7c8b919c to your computer and use it in GitHub Desktop.
brute force -> TLE
public int getSmallest(int number, int k) {
String sn = String.valueOf(number);
BigInteger bi = new BigInteger(sn), bk = BigInteger.valueOf(k), z = BigInteger.ZERO;
//odd/even = -1
if(number%2!=0 && k%2==0) return -1;
int c=1;
String s = sn;
while(bi.mod(bk)!=z){
//extend
s += sn;
bi = new BigInteger(s);
c++;
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment