BC160 小q的数列
小q的数列
https://www.nowcoder.com/practice/76796815518f4db5b800775581cda1e4?tpId=290&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D290
import java.util.Scanner; // 逻辑应该是对的 只是未在规定时间内输出 // 可是我不加N'的逻辑,只是接收加一个输出就已经超时了 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { long n = sc.nextLong(); int value = 0; // fn = n的二进制数中的1的个数 String ss = Long.toBinaryString(n); for (int j = 0; j < ss.length(); j++) { if (ss.charAt(j) == '1') { value ++; } } long n1 = (long)(Math.pow(2, value) - 1); System.out.println(value + " " + n1); // System.out.println(n + " "); } } }