题解 | #计数器#
计数器
http://www.nowcoder.com/practice/e953b0dc87bb43f29cb042c7a9f31598
import java.io.*; import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNextLong()){ long n = sc.nextLong(); System.out.println(fun(n)); } } public static long fun(long n){ if(n <= 3){ return 3 - n + 1; } int index = 1; long num = n; while(num > 3 * Math.pow(2, index - 1)){ num -= 3 * Math.pow(2, index - 1); index++; } return 3 * (long)Math.pow(2, index) - 2 - n; } }