TouchStone
  请登录后使用
登录 注册
距离CSP第一轮: ??天 距离CSP第二轮: ??天 距离NOIP还有: ??天
 系统首页  练习题库  考试列表  判题结果  信息发布  解题排行
  • 首页
  • 题库
  • P4463
  • 题目
  • P4463Build a tree
    限制 : 时间限制 : 1000 MS   空间限制 : 565536 KB
    问题描述

    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−1) / k⌋. 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