Product of Divisior : Why i got WA??

  • help me out from here please

  • Problem link…

  • what is wrong with my solution??

    using namespace std;
         **//driver program...**
       int main(){

                  	long long int T,N,i,j,K,arr[500001];

    	        for(i=1 ;i <= 500000;i++)        arr[i]=1;




		       if(N==1) printf("\n");
		       else if(arr[N]==0) printf("0000\n");
		       else printf("%lld\n",arr[N]);

          	    return 0;

I guess your ‘ct’ array stands for number of divisors and you are counting all divisors so that you can answer each query as (total divisors/2) ^ N which takes O(log(n)) time per query and O(n*log(n)) pre-processing. Instead of increasing ‘ct’ by 1 everywhere, you can instead multiply it by i. Obviously this means you initialize ct as 1 for all elements. Also now you don’t have to care about square root stuff. Each query can be answered simply as ct[n] which is O(1) !

1 Like

@sumeet_varma again TLE…

@sumeet_varma …what should be ans for N==1??