Are You A Prime Number

后端 未结 11 2175
甜味超标
甜味超标 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 07:51

    A simple improvement would be to change the for loop to break out when it finds a factor:

       for (i = 2; i <= ceiling && !factorFound; i++) {
            if (input % i == 0) {
                factorFound = 1;
    

    Another possibility would be to increment the counter by 2 (after checking 2 itself).

提交回复
热议问题