F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Build a tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1826    Accepted Submission(s): 697


Problem Description
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 $\lfloor\frac{i-1}{k}\rfloor$. HazelFan wonders the size of every subtree, and you just need to tell him the XOR value of these answers.
 

Input
The first line contains a positive integer $T(1\leq T\leq5)$, denoting the number of test cases.
For each test case:
A single line contains two positive integers $n,k(1\leq n,k\leq10^{18})$.
 

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

Sample Input
2 5 2 5 3
 

Sample Output
7 6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:00:37, Gzip enabled