current position:Home>Why is the range of the second for loop < I-1?

Why is the range of the second for loop < I-1?

2022-02-02 21:44:55 CSDN Q & A



Refer to the answer 1:

Refer to the answer 2:

Refer to the answer 3:

k<i-1 No need at all . If you don't want trouble , Write a k<i Just go . Think of less code loops , It can be written in two ways ,
One is k*k<=i, For example, calculation 16 Is it a prime number , You can count 4 That's all right. .
Or first define a variable equal to sqrt(i), then k<= This variable also works , The number of cycles is the same . It is not recommended that sqrt(i) Write in a loop statement , This will be performed every time sqrt(i), It takes time .

Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended