import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
while(true){
int x=Integer.parseInt(br.readLine());
if(x==0)
break;
int counter=1;
while(!last(x,counter)){
counter++;
}
sb.append(counter).append("\n");
}
System.out.print(sb);
}
static boolean last(int x,int m){
Queue<Integer> qu=new LinkedList<Integer>();
for(int i=2;i<x+1;i++){
qu.add(i);
}
for(int i=0;qu.size()>1;i++){
for(int j=0;j<m-1;j++){
qu.add(qu.remove());
}
int temp=qu.remove();
if(temp==2)
return false;
}
return true;
}
}
No comments:
Post a Comment