All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself.
This time Sheriff gathered all the bandits in his garden and ordered them to line up. After the whistle all bandits should change the order in which they stand.
Sheriff gave all the bandits numbers from 1 to N. For each place i he determined the unique position j. After whistling the bandit staying on position i should run to the j-th position. Sheriff loved seeing how the bandits move around, and he continued whistling until the evening. He finished the game only when he noticed that the bandits are in the same order in which they were standing originally.
Now the Sheriff asks the question: How many times has he whistled?
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of bandits. The second line contains N space-separated integers A1, A2, ..., AN denoting that the bandit staying on position i should run to the Ai-th position after the whistle.
Output
For each test case, output a single line containing number of times the sheriff had to whistle, print it modulo 10^9 + 7.
Constraints
1 ≤ T ≤ 5
1 ≤ N ≤ 100000
All Ai are distinct numbers from 1 to N
Now, I did not incorporate the "number of test cases option & have taken input of integers in a diff order..Pls help me with the code..my code is as follows, it has a runtime error..
#include <iostream>
#include <string>
using namespace std;
class bandits
{
public:
int *a,*ac,*t;
int size;
Line 16: You're trying to store into ac[0], but ac has never been allocated.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
To be specific, the code has no compile time errors...as soon as take the input input at line 24, the loop is working fine..just after the execution of the loop, a runtime error is occurring.