1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class 最幸运的人 { 5 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 9 Scanner scanner = new Scanner(System.in); 10 int N=scanner.nextInt(); 11 ArrayList<Integer> arrayList = new ArrayList<>(); 12 for(int i=1;i<=N;i++) { 13 arrayList.add(i); 14 } 15 int j=0,k=0; 16 while(arrayList.size()!=1) { 17 if(++j%3==0) { 18 arrayList.remove(k); 19 k--; 20 } 21 if(++k>=arrayList.size()) { 22 k=0; 23 } 24 } 25 System.out.println(arrayList.get(0)); 26 } 27 28 }