Untitled
unknown
c_cpp
a year ago
875 B
2
Indexable
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(); } }
Editor is loading...