小爱有一个奇怪的计数器。在第一个时刻计数器显示数字3,在接下来的每一个时刻,屏幕上的数字都会减1,直到减到1为止。
接下来,计数器会重置为上一个计数周期初始值的两倍,然后再每一个时刻减1。具体过程如下图所示:
找出规律,并打印出t时刻计数器的值。
import math class MainActivity: def main(self): # Read the data t = int(input()) # Calculate the result k = math.log2(t / 3 + 1) if math.floor(k) == k: print(1) return k = math.floor(k) result = 3 * 2 ** k - (t - 3 * (2 ** k - 1)) + 1 print(result) if __name__ == '__main__': M = MainActivity() M.main()