I need to primitive root of prime number?
<p>I need to primitive root of prime number.I wrote this code but it has heap size error and it doesn't work for big number like 101.I don't have any other idea for calculating primitive root .If you have please help me .I need to it so much.Do you have any other algorithm for calculating primitive root of prime number?</p>

<pre><code>static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; list1=new  ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();

private static int primitiveRoot(int prim){

        ArrayList&lt;ArrayList&lt;Integer&gt;&gt;  number=new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();// this has all sequence numbers of x power of 0 to prime-1
        ArrayList&lt;Integer&gt; sublist=new ArrayList&lt;Integer&gt;();

        for (int x=2;x&lt;prim;x++ ){
            sublist = new ArrayList&lt;Integer&gt;();
            for (int power=0;power&lt;prim-1;power++){
                int i=(int)((Math.pow(x, power))%prim);
                sublist.add(i);     
            }

            number.add(sublist);

        }

        for (int j=0;j&lt;number.size();j++){
                for (int m=0;m&lt;list1.size();m++){
                    if(number.get(j).equals(list1.get(m)) ){// element of number arraylist compare to list1,equality means that we find one of primitive root
                        a=j+2;
                         break;
                    }
                }

        }

        return a;// this is primitive root

    }
</code></pre>

<p>list1 is an arraylist of arraylists ,It contains all permutations of numbers between 1 to prime-1.It only work for small prime number like 7 or 11 .I increased heap size but It didn't effect.</p>
