Skip to content

Instantly share code, notes, and snippets.

@thaim
Created May 5, 2014 20:31
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 thaim/f2083c57bc5b18bba1a8 to your computer and use it in GitHub Desktop.
Save thaim/f2083c57bc5b18bba1a8 to your computer and use it in GitHub Desktop.
SRM619Div2Medium (500pt)
import java.util.ArrayList;
import java.util.List;
public class ChooseTheBestOne {
public int countNumber(int N) {
int idx = 0;
List<Integer> remain = new ArrayList<Integer>();
for (int i=0; i<N; i++) {
remain.add(i+1);
}
for (int i=1; i<N; i++) {
int size = remain.size();
int th = (int)(((long)Math.pow(i, 3)-1) % size);
remain.remove((idx+th)%size);
idx = (idx+th)%size;
}
return remain.get(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment