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：
Yes, but not necessarily , Look what you wrote .
k<i-1 It is not necessary to , It can be written. k<i/2+1 perhaps k<=sqrt(i)
Cycle termination conditions , Is to find a valid threshold .
Judgement primes ,k<=sqrt(i) This condition is the most effective . When k>sqrt(i) after , There must be no divisible number .
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：
author[CSDN Q & A],Please bring the original link to reprint, thank you.
The sidebar is recommended
- *PTR is a value and a is a pointer. How can they be equal? Shouldn't it be * PTR = & A?
- Specify local time to run code?
- Why is a < B short circuited?
- Usually in face recognition, what operations do we need to do (such as division)? How many times does each operation need to be done? What is the data specification of the operation?
- Firefox browser of win10 system is not connected to the Internet
- Must JNA load DLL be an absolute path? The relative path will report an error every time it is loaded lang.UnsatisfiedLinkError
- Server error in '/ CMS parameters' application.
- The MAC installs windows virtual machine and QT reports an error
- On string array as function parameter
- How to figure out HTML5
guess what you like
What is the specific idea to realize the comment function
The number of occurrences of certain fields in SQL query
Programming with eclipse Java
Get function usage, how to use, high adoption rate
MNIST dataset with KNN algorithm
The so-called palindrome number is the same number from left to right and from right to left. For example, 121 is a palindrome number. Write a program to find the number of palindromes that can be divided by 3 in the range of 100-m. (can anyone see where
Solve the problem of binding this point in anti chattering throttling
Find the factorial of 0-5 by function
JSP get the current URL parameter
Why does this program time out?
- Why did you output more
- Text file problem output new file
- Guess numbers and write programs in C + +
- For the field of int type set, when 0 is entered, the database is null and empty
- Design a mathutils Java class file
- The problem of C language do while loop
- Using random class, randomly generate five integers between 1 and 100, add the generated random integers to a list set, and then calculate the sum of all numbers in the set
- Python pyecharts draws a line chart, and the line breaks randomly
- When the ie11 browser fetches local files, it gets stuck for about 1 minute. How can I solve it?
- How can we understand the data structure and algorithm?
- It is said that the new project given by the company can run before. Now I run and report this error, and I don't know why to add the GIT of the configuration file. Can you help me have a look
- Import data into the database and analyze it
- In vue3 setup, the data change of the object cannot be observed by the watch, and the reason is unknown
- Single chip microcomputer four digit nixie tube rolling display 0-F
- The applet customizes the slider slider and makes the number in decimal form
- How to solve the problem that the time caused by VPN is not the same as the system time?
- Is there anyone to answer
- 2. If there are multiple catches in a program segment, which of the following conditions will the program execute?
- Why delete an element in the set and return 1 Σ (っ ° Д °;) っ？
- GetElementsByTagName ('li ') whether to obtain Li elements of the same level or all Li elements in it
- Why is the time complexity of nested while loops in for still o (n)
- Spring cannot load the context. What's the problem
- What's the problem, please
- C language reading program, why 5? Seek explanation
- How can the Java background distinguish the clients of different users when the company has the same LAN
- Batch import needs to be added in the system
- I can't even paste it a little
- The input value is incorrect. There are two inputs, but only one can be entered
- Why judge whether the triangle is wrong and how to write it.
- How to solve the hidden bug of fluent Web text overflow overflow
- C sharp mouse penetration
- Idea uses el and JSTL expressions respectively, which are written in JSP files and display blank space on the web. What's the problem.
- H3C help me, you fool. I really didn't attend class
- What's the problem with not running at all
- How to open with sqlyog Enterprise Edition MDF and LDF files. SQL Server2008 is not used in class teaching
- C language and application file programming program
- What does the code in Android XML mean? Please have a look
- The branch jump instruction in risc-v requires several branch delay slots
- No change with non singleton labels? What's wrong