Solution :
This file contains hidden or 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
/// Author : Shohan | |
/// Problem Type : Josephus Problem | |
#include<stdio.h> | |
int josephus(int a,int b); | |
int main() | |
{ | |
int n,m,p; | |
while(scanf("%d %d",&m,&n)==2){ | |
p=josephus(m,n); | |
printf("%d\n",p); | |
} | |
return 0; | |
} | |
int josephus(int n,int k) | |
{ | |
if(n==1) | |
return 1; | |
else | |
return (josephus(n-1,k)+k-1)%n+1; | |
} |