Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created April 30, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/0fbbc8dde677e75bed21fc6c4d2722b9 to your computer and use it in GitHub Desktop.
Save vrat28/0fbbc8dde677e75bed21fc6c4d2722b9 to your computer and use it in GitHub Desktop.
public List<Integer> powerfulIntegers(int x, int y, int bound) {
Set<Integer> set = new HashSet();
for(int i=1; i<=bound; i*=x) {
for(int j=1; i+j <= bound; j*=y) {
set.add(i+j);
if(y == 1) break;
}
if(x == 1) break;
}
return new ArrayList(set);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment