Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Thank Glyxerine! At least I know I'm on the right track.
I just can't think how to logically limit the upper bound of the loop since I don't know how large the int could be. I mean, it could be (858 Trillion + 1) so in theory I would need a loop that would go that high, wouldn't i?
Your solution is right but upper bound of loop is too high. Think about it :)
I still havn't solved this one yet so please take what I say with a grain of salt
But the issue I had using 6k+1 is that it doesn't always give you prime numbers. For instance
k = 4
(6*4 + 1) = 25
25 isn't a prime number
WARNING: Just signed up for the site earlier today so I apologize in advance if I'm not following the proper etiquette
But I'm trying this 'Kata' and I'm having the same issues I see a lot of other people having (though the reply comments have been hidden, hence why I'm making this post) where when I run this in C++ it passes all the sample test but when I hit Attempt I get the "Execution Timed Out (12000ms)"
Now here is what I have gathered so far:
-It is passable
-The issue is with the effiency with my code (clearly)
So I'm really just looking for some guidance to point me the correct direction (so please don't just give me the answer, that's not what I'm looking for). Because as of right now, I'm not sure how else I could optomize the code. (I'm not sure if I'm allowed to post my code so I'll just run down the logic)
I have a check to see if the int is <= 1, if so return false (prime numbers must be greater than 1)
A check to see if it equals 2, if so return true (2 is a prime number)
A check to see if it qeuals 3, if so retrun true (3 is a prime number)
A check to see if it equals 5, if so return true (5 is a prime number)
A check to see if the last digit is 0, 2, 4, 5, 6, 8 (num % 10 == x with x being each of those numbers), if so return false (since prime numbers can only end with 1, 3, 7, or 9)
Then after that I have a for loop with a standard prime number check (int i =2; i <=num/2; i++), and I know this is where my run time exceeds the limit. But I'm not sure what other methods there are to check for prime numbers without making a loop.
Again new to the site and still new to programming so please bear with me.
And thank you in advance for any feedback!