I - Intense Bit Wheel (二进制,bitset)

 SDUT 2022 Summer Individual Contest - 2(for 21) - Virtual Judge

 

There is a new intense giant wheel in UNAL town, in UNAL town the wheels move in counterclockwise direction, also as this wheel has n cabins, everyone and everything can play. In particular, numbers come to this attraction. However, a complete number doesn't fit in one cabin, in fact, each cabin have space only for one bit. For this reason a number splits into its binary from and ride the wheel each bit per cabin. As numbers do not want to mess it up, the bits enter into the attraction in the same order the number is formed. Nonetheless, the wheel moves k times (entering and exiting from the attraction don't count as moves), then when the bits have to get out of the wheel they probably don't do it in the same order they entered, therefore making a different number.

For example, when the number 13 enter in a intense 8-bit it will look like the left side of the image below, after 5 moves the wheel will look like the right side of the image, in this case the number exiting the wheel will be 161.

You as the chief of the numbers in the UNAL town want to know how the wheel can affect the numbers that ride this attraction.

Input

First line of input contains 2 numbers n (1 ≤ n ≤ 50) and m (1 ≤ m ≤ 1000) - the quantity of cabins in the wheel and the quantity of numbers that ride in the wheel, respectively.

Next m lines of input contains each 2 integers num (0 ≤ num < 2n) and k (1 ≤ k ≤ 1018) - the number that ride the wheel and the quantity of times the wheel move, respectively.

Output

For each number that ride the wheel print the resulting number after leaving the wheel. Output this number in its decimal form.

Example

input

Copy

8 3
1 1
13 5
17 12

output

Copy

2
161
17

Note

Note that all numbers that ride into the wheel have exactly n bits, for example the number 13 in a 8-cabin wheel is not 1101 but 00001101 (see example).

#include <bits/stdc++.h>
using namespace std;
void TLE() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
#define int long long
typedef long long ll;
const int N = 1e5 + 10;
const ll mod = 1000000007;
int e[N],ne[N],h[N],w[N],cnt=0;
map<char,int>mp;
typedef pair<int,int>PII;
vector<int>vec;
signed main()
{
    TLE();
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        vec.clear();
        int a,b;
         cin>>a>>b;
        while(a&&vec.size()<n)
        {
            vec.push_back(a&1);//求出a的二进制,并倒着存
            a>>=1;
        }
        while(vec.size()<n)
            vec.push_back(0);//不够的用0补齐

        int res=0;
        for(int i=n-b%(n);i<vec.size();i++)//逻辑模拟左移位,实际数组没有动
        {
            if(vec[i]==1)
            res+=pow(2,i-n+b%n);
        }
        for(int i=0;i<n-b%n;i++)
        {
            if(vec[i]==1)
            res+=pow(2,i+b%n);
        }
        cout<<res<<endl;
    }
}

 

题意:

题目废话很多,其实我也读不懂,从样例出发,比如这个13和5,
就是给你一个以8位为循环节的二进制数,把13的二进制位左移5位,移过了界就%8,再求求这个值是谁。
思路:打cf位运算用的比较多了,做起来比较轻松。直接枚举13二进制位,看是不是1,1的话就给它开个数组在下标+5的那个地方存下来,别忘了%8。最后看看这个数组的那些下标是1,用2的次幂去求和。
 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值