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.
letans=0if(n===1)return"Bob"elseans++// because n>0functionisPrime(i){// optimal the loop conditionletlimit=Math.round(Math.sqrt(i))for(letmod=2;mod<=limit;mod++){if(i%mod===0){returnfalse;}}returntrue}// eleminate the even number except 2 to optimal the loopfor(leti=3;i<=n;i+=2){if(isPrime(i))ans++}returnans%2===0?"Bob":"Alice"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Alice and Bob's Silly Game
You are viewing a single comment's thread. Return to all comments →
JavaScript Solution