DCan someone take a look into my code and why does it fails on 18 and 20 test case on time ? when I test it home for limit number it work's fast ?
http://www.z-trening.com/new/www/html/submit.php?submit=7100054306&subm_code=1
RAs I can see your solution's complexity is f(n)=largest prime divisor of n,
so if n=p prime, then it takes O(n) time, too large!
You can factorize in O(sqrt(n)) time in every case. Use that.
DI don't understand what are you meaning?
DSolved please delete the topic...
mhttp://www.z-trening.com/new/www/html/submit.php?subm_stat=1&submit=7100054585
what am i doing wrong ?
mcan anybody look at my code and write what am i doing wrong ?
hChange 'IsP'. Try:
bool isP(lnt a){
int q = sqrt ( a );
for(lnt x=2;x<=q;++x){
if(a%x==0)return false;
}
return true;
}
mthat's the same thing,
x*x <= a , or x <= sqrt(a)
sTry to do the same, without checking wheter the number is prime or not... :)
mstil fails on time at 17. TC
http://www.z-trening.com/new/www/html/submit.php?subm_stat=1&submit=7100054767
sYou don't need isP() function, I think you can simply delete her... :)