CF1734F.Zeros and Ones
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let S be the Thue-Morse sequence. In other words, S is the 0 -indexed binary string with infinite length that can be constructed as follows:
-
Initially, let S be "0".
-
Then, we perform the following operation infinitely many times: concatenate S with a copy of itself with flipped bits.For example, here are the first four iterations:
Iteration S before iteration S before iteration with flipped bitsConcatenated S 1010120110011030110100101101001401101001100101100110100110010110 … … … …
You are given two positive integers n and m . Find the number of positions where the strings S0S1…Sm−1 and SnSn+1…Sn+m−1 are different.
输入格式
Each test contains multiple test cases. The first line of the input contains a single integer t ( 1≤t≤100 ) — the number of test cases. The description of the test cases follows.
The first and only line of each test case contains two positive integers, n and m respectively ( 1≤n,m≤1018 ).
输出格式
For each testcase, output a non-negative integer — the Hamming distance between the two required strings.
输入输出样例
输入#1
6 1 1 5 10 34 211 73 34 19124639 56348772 12073412269 96221437021
输出#1
1 6 95 20 28208137 48102976088
说明/提示
The string S is equal to 0110100110010110....
In the first test case, S0 is "0", and S1 is "1". The Hamming distance between the two strings is 1 .
In the second test case, S0S1…S9 is "0110100110", and S5S6…S14 is "0011001011". The Hamming distance between the two strings is 6 .