just not the super obvious one that demonstrates extremely basic understanding of what a prime number is
yes, we expect professional software developers to have basic maths skills
"what is a prime number" is taught to 7 year olds, it's not vector calculus
what else would you consider to be an unreasonable thing for an employer to require?
reading and writing skills of a typical 7 year old?
Second, basic math still that you never or rarely use or with very large time between usage might get rusty. You may understand the concept but not find the optimal solution. The way you are responding here shows quite a lot about how you are short sighted by instant-failing someone with a single question instead of trying to asses the whole person as much as you can. On you side, you are wasting opportunity to have a great person that could be a key player in your team by bringing other set of skill on the table.
Look, if you think this sort of thing allows you to identify great candidates, good for you. But in my experience, not only is this kind of practice stupid on its face, but it leads to engineering orgs packed with people who are good at memorizing trivia but terrible at solving real problems.
> yes, we expect professional software developers to have basic maths skills
Skill != knowledge. "What is a prime number" can be looked up and understood by any competent programmer in <5 minutes.
> "what is a prime number" is taught to 7 year olds, it's not vector calculus
Then it's reasonable to expect that an interviewee would be able to learn it as well, given the same resources. It does not however follow that an interviewee would inherently have that knowledge, just because 7 year olds are taught it.
Bottom line is, you're making too many assumptions about complete strangers.
+1 is not a good idea since ~half of all numbers are effectively non-prime simply by being even numbers.
You can double the speed by using +2 without using any fancy tricks, just changing a single character.
Common approach is to use square roots, this reduces the runtime. Recommend checking out project euler if you like solving hard math-code-o(n)-puzzles.
Yes it makes sense (in the GPT code) that you'd only go up to i * i ... although looking at pythonic while: statements is just gross to me in this context, it would feel a lot more readable to say, e.g. in PHP:
for ($i=2;$i<sqrt($n);) { $i+=($i==2 ? 1 : 2); //although the first one should just be outside the loop }