We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is my code... it ran fine upto 10^8 on codechef. don't knw why hackerrank can't run it after around 835000... pls help
#include<bits/stdc++.h>usingnamespacestd;inlinelonglongpow2(longlonga){returna*a;}inlinelonglongpow3(longlonga){returna*a*a;}inlinelonglongpow4(longlonga){returna*a*a*a;}intmain(){longt;cin>>t;longmx=-1;longa[t];for(longi=0;i<t;i++){cin>>a[i];if(a[i]>mx)mx=a[i];}intb[mx+1];for(longi=0;i<mx+1;i++)b[i]=0;intpr=pow(100000000,0.5)+1;vector<long>primes;primes.push_back(2);for(intk=3;k<=pr;k++){boolisPrime=true;for(autop:primes){if(k%p==0){isPrime=false;break;}}if(isPrime)primes.push_back(k);}intx=primes.size();longlongsum=0;for(inti=0;i<x;i++){sum=0;sum+=pow4(primes[i]);if(sum>mx){sum-=pow4(primes[i]);break;}for(intj=0;j<x;j++){sum+=pow3(primes[j]);if(sum>mx){sum-=pow3(primes[j]);break;}for(intk=0;k<x;k++){sum+=pow2(primes[k]);//cout << sum << endl;if(sum>mx){sum-=pow2(primes[k]);break;}b[sum]=1;sum-=pow2(primes[k]);}sum-=pow3(primes[j]);}sum-=pow4(primes[i]);}for(longtt=0;tt<t;tt++){longlongres=0;for(longi=0;i<a[tt]+1;i++)res+=b[i];cout<<res<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #87: Prime power triples
You are viewing a single comment's thread. Return to all comments →
this is my code... it ran fine upto 10^8 on codechef. don't knw why hackerrank can't run it after around 835000... pls help