Untitled

mail@pastecode.io avatar
unknown
c_cpp
6 months ago
875 B
1
Indexable
Never
import java.util.Scanner;

public class TasteOfNumber {
    
    // Function to get the number of set bits
    public static int countSetBits(int n) {
        int count = 0;
        while (n > 0) {
            count += n & 1;
            n >>= 1;
        }
        return count;
    }
    
    public static int nextSameTasteNumber(int n) {
        int originalCount = countSetBits(n);
        while (true) {
            n++;
            if (countSetBits(n) == originalCount) {
                return n;
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        
        for (int i = 0; i < T; i++) {
            int N = sc.nextInt();
            System.out.println(nextSameTasteNumber(N));
        }
        
        sc.close();
    }
}