Created
February 11, 2018 05:53
-
-
Save zhanggang807/da311a24ac628fb6b754028ba2a18c0a to your computer and use it in GitHub Desktop.
Josephus Circle Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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