DPower Permutations

All submissions for this problem are available.
Let N be a positive integer and S = {1, 2, 3, ..., N}. For a given positive integer d the function f : S > S is called dpower permutation if there exists a bijection g : S > S such that g ( g ( ... g ( x ) ... ) ) = f(x) for each x from S , where g is repeated exactly d times.
You are given some bijection f : S > S and a positive integer D. You need to find the number of those d <= D such that f is dpower permutation.
Input
The first line contains a single positive integer T <= 10, the number of test cases. T test cases follow. The first line of each test case contains two positive integers N and D, where N <= 700 and D <= 10^{18}. The second line contains N spaceseparated integers. i^{th} number in the second line is the value f(i). It is guaranteed that f is bijection from S onto S.
Output
For each test case, output a single line containing the answer for the corresponding test case.
Example
Input: 2 3 6 1 2 3 5 10 2 1 4 5 3 Output: 6 3
Explanation
In the second case the appropriate values of d is 1, 5 and 7.
Author:  anton_lunyov 
Tester:  rajivka 
Editorial  http://discuss.codechef.com/problems/DPOWPERM 
Tags  anton_lunyov, cook11, hard 
Date Added:  11062011 
Time Limit:  0.52 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 