Responsive image

问题 1857 --Build a tree

1857: Build a tree

时间限制: 2 Sec  内存限制: 128 MB
提交: 7  解决: 6
[提交][状态][讨论版][命题人:]

题目描述

HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled ⌊i−1k⌋. HazelFan wonders the size of every subtree, and you just need to tell him the XOR value of these answers.
 

输入描述

The first line contains a positive integer T(1≤T≤5), denoting the number of test cases.
For each test case:
A single line contains two positive integers n,k(1≤n,k≤10^18).
 

输出描述

For each test case:
A single line contains a nonnegative integer, denoting the answer.
 

样例输入

2
5 2
5 3

样例输出

7
6

来源

 

[提交][状态]
ACM算法攻关部
  • Anything about this OnlineJudge, Please Contact Administrator. Click add QQ

    OJ system based on HUSTOJ Project , UI based on Twitter Bootstrap

    Copyright 2016 ACM算法攻关部
    关于网站改版