I tried this problem but still i don't understand it this is my program in C++
`
#include <iostream>
#include <cmath>
using namespace std;
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
void long_pow(long long n, int div);
int primes[] = {0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701};
int prod[500001] ={0};
bool done[500001] = {false};
void calc_product(int n)
{
if(prod[n]==0)
{
int index = 1;
int n1 = n;
bool flag = false;
int total = 1;
int cur = 1;
while(n!=0 && index<=126 &&(!flag) )
{
//checking if it is prime
if(n1 == primes[index]) break;
if(n%primes[index]==0)
{
cur++;
// total = total*primes[index];
n/=primes[index];
}
else
{
if(n==1) flag = true;
// cout<<primes[index]<<" "<<cur<<" "<<n<<endl;
total = total*cur;
index++;
cur = 1;
}
}
if(n>1) total*=2;
//cout<<total<<endl;
// long_pow(n1,total);
prod[n1] = (int)pow((double)n1,(total-2)/2);
//now printing
if(done[n1])
{
printf("%d%d%d%d",prod[n1]/1000,(prod[n1]%1000)/100,(prod[n1]%100)/10,prod[n1]%10);
}
else
printf("%d",prod[n1]);
}
else
{
if(done[n])
{
printf("%d%d%d%d",prod[n]/1000,(prod[n]%1000)/100,(prod[n]%100)/10,prod[n]%10);
}
else
printf("%d",prod[n]);
}
//cout<<<<endl;
}
void long_pow(long long n, int div)
{
long long n1 = n;
bool flag = false;
long long total = 1;
//not including the number itself
if(div%2 == 0)
{
div = div/2;
for(int i=1;i<div;i++)
{
total = total*n;
if(total>9999)
{
flag = true;
total%=10000;
}
if(flag)
total%=10000;
}
}
else
{
n = (int)sqrt((double)n);
for(int i=1;i<div-1;i++)
{
total*=n;
if(total>9999)
{
flag = true;
total%=10000;
}
if(flag)
total%=10000;
}
}
done[n1] = flag;
prod[n1] = total;
/*if(flag)
{
cout<<total/1000<<(total%1000)/100<<(total%100)/10<<total%10;
}
else
cout<<total;
*///return total;
}
int main()
{
int cases;
scanf("%d",&cases);
while(cases)
{
int i;
scanf("%d",&i);
// for(i=2;i<=500000;i++)
calc_product(i);
cases--;
if(cases) printf("\n");
}
//total time
printf("time=%.3lf sec.\n",
(double) (clock())/CLOCKS_PER_SEC);
getch();
return 0;
}
now the problem is this is still not sufficient to solve the problem.. i have precomputed my list of primes and and decomposing the number into the prime factors still..got problem .. plz tell me where do i go to ..or help me make my method faster ...