Mathophobia(MATHP).I'm getting TLE.Please help

I have written the code for this problem but I can’t understand why my code is slow.I have written on java , and to calculate the prime numbers I used sieve Of Eratosthenes and saved all the prime numbers in a HashMap.Please forgive my english.

static void dri(int n) {
        long large=0;int r=0,x,count=0,p,count1=0;

        //To understand why I calculated x let's take an example
        //let n=530 sqrt(530) is 23 so for all the numbers greater than 23 when 
        //we square them they will come out to be greater than n.I think you get 
        //what I'm trying to explain

        while(r<x) {
            r = map.get(++count); // Prime numbers will be stored in r
            int exp = (int) (Math.log(n) / Math.log(r));
            //I'm trying to calculate the x in r^x=n.
            if (exp != 1) {   //This is just to resolve an error dont mind this line
                if (map.containsValue(exp) == false) { 
                    count1 = exp;
                    while (!map.containsValue(--count1)) ;  
                        //As I need a^b where a and b are prime so I have to 
                          calculate the nearest prime number to exp
                    exp = count1;
                int temp = (int) Math.pow(r, exp);
                if (large < temp)
                    large = temp;

Precompute the seieve for max possible value of N. Don’t compute it again for every test case.