Question: Calculate the nth number in the number set consisting of {2, 3, 5, 7.
Analysis: Four pointers are used to correspond to the current corresponding factor of each number. The minimum value is obtained each time and the pointer is moved back. Pay attention to equal conditions.
Note: The output count.
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
Int d [5850];
Int v [4] = {2, 3, 5, 7 };
Int p [4] = {1, 1, 1 };
Int main ()
{Www.2cto.com
Int count = 2; d [1] = 1;
While (count <= 5842 ){
Int min = 2000000001;
For (int I = 0; I <4; ++ I)
If (min> v [I] * d [p [I])
Min = v [I] * d [p [I];
For (int I = 0; I <4; ++ I)
If (min = v [I] * d [p [I])
P [I] ++;
D [count ++] = min;
}
Int n;
While (scanf ("% d", & n ){
Printf ("The % d", n );
If (n % 100 = 11 | n % 100 = 12 | n % 100 = 13)
Printf ("th ");
Else if (n % 10 = 1)
Printf ("st ");
Else if (n % 10 = 2)
Printf ("nd ");
Else if (n % 10 = 3)
Printf ("rd ");
Else printf ("th ");
Printf ("humble number is % d. \ n", d [n]);
}
Return 0;
}