Are You A Prime Number

后端 未结 11 2178
甜味超标
甜味超标 2021-02-10 07:39

I\'ve been interested in the problem of finding a better prime number recognizer for years. I realize this is a huge area of academic research and study - my interest in this i

11条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 08:09

    Even numbers(except 2) cannot be prime numbers. So, once we know that the number is not even, we can just check if odd numbers are it's factors.

    for (i = 3; i <= ceiling; i += 2) {
            if (input % i == 0) {
                factorFound = 1;
                break;
            } 
        }
    

提交回复
热议问题