Created
February 2, 2018 05:29
-
-
Save meriy100/ed21852dad87e81cac2f0b323b30cc05 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
int josephus ( int n ) { | |
int result ; | |
if ( ( n == 1 ) || ( n < 1 ) ) { | |
return 1 ; | |
} | |
else if ( n % 2 == 0 ) { | |
result = 2 * josephus ( n / 2 ) - 1 ; | |
return result ; | |
} | |
else { | |
result = 2 * josephus ( n / 2 ) + 1 ; | |
return result ; | |
} | |
} | |
int main ( void ) { | |
int n ; | |
while ( ( scanf ( "%d" , & n ) ) == 1 ) { | |
printf ( "%d\n" , josephus ( n ) ) ; | |
} | |
return ( 0 ) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment