Josephus Flavius was a famous Jewish historian of the first century at the time of the Second Temple destruction. During the Jewish-Roman war he got trapped in a cave with a group of n soldiers surrounded by romans. The legend has it that preferring suicide to capture, the Jews decided to form a circle and, proceeding around it, to kill every second remaining person until no one was left. Josephus, not keen to die, quickly found the safe spot in the circle and thus stayed alive.
#include<stdio.h>
void main()
{
int a=1,n,j=1,i;
clrscr();
printf("\n Enter the number \n");
scanf("%d",&n);
while(a<n)
{
a=a*2;
printf("\n%d ",a);
}
if(a==n)
{
printf("\n The number entered is a power of 2");
printf("\n the answer is 1");
}
else
{
a=a/2;
n=n-a;
for(i=1;i<=n;i++)
{
j+=2;
}
printf("\n the answer is %d",j);
}
getch();
}
Responses
0 Respones to "Josephus Flavius problem for everywhich 2"
Post a Comment