Aiiage Camp Day3 B Bipartite
题意
给出T个N,判断哪些是2的整数次幂。
T<=10, N<=1e100000.
题解
N & (N - 1) == 0即为2的整数次幂。
学好Java,做遍大数都不怕。
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main 5 { 6 public static void main(String[] args) 7 { 8 Scanner cin = new Scanner(System.in); 9 int T; 10 T = cin.nextInt(); 11 for (int ii = 0; ii < T; ++ii) 12 { 13 BigInteger n = cin.nextBigInteger(); 14 if (n.compareTo(BigInteger.ZERO) > 0) 15 { 16 BigInteger ans = n.and(n.subtract(BigInteger.ONE)); 17 if (ans.compareTo(BigInteger.ZERO) == 0) 18 System.out.println("Yes"); 19 else 20 System.out.println("No"); 21 } 22 else 23 { 24 System.out.println("No"); 25 } 26 } 27 } 28 }