Job Recruitment Website - Zhaopincom - I attended an interview with an IT company today, but I didn't get two open-ended questions. Who can help me explain the answer and the truth?
I attended an interview with an IT company today, but I didn't get two open-ended questions. Who can help me explain the answer and the truth?
If K locks are arranged in the corridor in turn, then after the K-th pass, there are locks 1, 4, 9, 16 ..., | sqrt (k) | locks have been opened.
Proof: 100 locks are marked as S 1, S2, S3, ..., Si, ..., respectively.
S 1 only switches in 1 pass;
If I is a prime number, si only switches at 1 and I times, and the switching times are even;
If I is a compound of non-square numbers, it can always be decomposed into I = m * n = q * p =...= r * u (m! =n,q! =p,....,r! =u), si is only at time 1, i, m, n, q, p, ..., r, u, and the switching times are even;
If I is a square number, I = m * n = q * p =...= r * u = x * x (m! =n,q! =p,....,r! =u), si is only at 1, i, m, n, q, p, ..., r, u, x times, and the switching times are odd;
The lock head is locked before switching, and it is still locked after switching several times;
Before switching, the lock is locked, and after odd switching, the lock becomes open.
Therefore, only when I is a square number will the lock be opened.
Algorithm: From the operation steps of solving puzzles, we can get inspiration and get the square number in this way.
Step 1: Set the status value of the number to-1;
Step 2: Make all numbers 1, 2, 3, ..., 100 according to this module, and change the state if the result is 0;
Step 3: Print out the number with the status value of 1.
Procedure: The following is the procedure for finding the square of the interval [1, 100] by this method. The code runs successfully on vc++6.0 platform.
/* * Author: Cartography
Date: February 2007.15
FindSquareNumber。 cpp**/
# include & ltiostream & gt
# include & ltprocess.h & gt
Use namespace std
void main()
{
int a;
int I;
for(I = 1; I<= 100; i++)
{
a =- 1;
for(int j = 1; j & lt= I; j++)
{
If (i%j==0)
a =(- 1)* a;
}
If (a== 1)
Cout & lt& lt "square number:"<& lt me<& ltendl.
}
System ("suspended");
}
- Related articles
- What else is there for breakfast besides steamed stuffed bun, fried dough sticks, bread and fried powder? Help? In Nanchang
- Where does the owner of Heyuan Construction Machinery come from?
- 233 online school special post teacher Shaanxi special post teacher registration column Shaanxi Shangluo Town An County special post teacher pre-school
- How much is the tuition fee for Anshan junior high school?
- Who owns Susong Yunmengze Company?
- How much is the second phase of Shanwei Anju Paradise?
- 20 16 how many people registered for the recruitment of 64 teachers in Hualong district, Puyang city?
- How about Pingliang Tiantai Real Estate Development Co., Ltd.?
- Zhangjiajie career salary
- Flagship models and pure electric vehicles BMW Group will launch 26 new products in China in 2022