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

ZYB's Tree

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1338    Accepted Submission(s): 425


Problem Description
$ZYB$ has a tree with $N$ nodes,now he wants you to solve the numbers of nodes distanced no more than $K$ for each node.
the distance between two nodes$(x,y)$ is defined the number of edges on their shortest path in the tree.

To save the time of reading and printing,we use the following way:

For reading:we have two numbers $A$ and $B$,let $fa_i$ be the father of node $i$,$fa_1=0$,$fa_i=(A*i+B)\%(i-1)+1$ for $ i \in [2,N]$ .

For printing:let $ans_i$ be the answer of node $i$,you only need to print the $xor$ $sum$ of all $ans_i$.
 

Input
In the first line there is the number of testcases $T$.

For each teatcase:

In the first line there are four numbers $N$,$K$,$A$,$B$

$1 \leq T \leq 5$,$1 \leq N \leq 500000$,$1 \leq K \leq 10$,$1 \leq A,B \leq 1000000$
 

Output
For $T$ lines,each line print the ans.

Please open the stack by yourself.

$N \geq 100000$ are only for two tests finally.
 

Sample Input
1 3 1 1 1
 

Sample Output
3
 

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-05-09 03:53:13, Gzip enabled