import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); while (scanner.hasNext()){ int n= Integer.parseInt(scanner.nextLine()); if(n==0){ break; } int[] ints=new int[n]; Arrays.fill(ints,1); int l=0; int size=n; while (size>1){ for(int i=0;i<n;i++){ if(ints[i]==1){ l++; } if(l==3){ ints[i]=0; size--; l=0; } } } for(int i=0;i<n;i++){ if(ints[i]==1){ System.out.println(i+1); } } } } } |
Double click to view unformatted code.