Skip to content

Instantly share code, notes, and snippets.

@zhanggang807
Created February 11, 2018 05:53
Show Gist options
  • Save zhanggang807/da311a24ac628fb6b754028ba2a18c0a to your computer and use it in GitHub Desktop.
Save zhanggang807/da311a24ac628fb6b754028ba2a18c0a to your computer and use it in GitHub Desktop.
Josephus Circle Solution
public class JosephusCircle {
public static void main(String[] args) {
int n = 0;
int m = 0;
int i = 0;
int s = 0;
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
n = scanner.nextInt();
}
if (scanner.hasNextInt()) {
m = scanner.nextInt();
}
for (i = 2; i <= n; i++) {
s = (s + m) % i;
}
System.out.println("The winner is " + s);
}
//http://www.cnblogs.com/EricYang/archive/2009/09/04/1560478.html
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment