1. 程式人生 > >Aiiage Camp Day3 B Bipartite

Aiiage Camp Day3 B Bipartite

args 判斷 new ext ati color ann -s int

題意

  給出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
}

Aiiage Camp Day3 B Bipartite