Page 1 of 1

please code in c++

Posted: Sun May 15, 2022 11:53 am
by answerhappygod
please code in c++
Please Code In C 1
Please Code In C 1 (60.58 KiB) Viewed 49 times
A Special Prime Number To find out a suitable prime number is very important for many algorithms, for example, RSA or hash table. Given a positive integer P, we name another positive integer Q as the SBN prime number of P. If the following conditions are true: (1) The number of I's digit in binary form of P and Q is the same. (2) Q is less or equal than P. (3) Q is a prime number. (4) Q is the largest number in accordance with the above conditions. For example: If P= 10, we can transfer Pinto binary form as 000010102. We can find that Q (the SBN prime number) of Pis 5 (000001012). 7 (000001112) is a prime number but the number of l's digit in binary form is not matched. 3 (000000112) is a prime number and the number of l's digit in binary form is also matched but it is not the largest number. Input Format The input of this problem is a sequence of unsigned integers (decimal form) as P. Each line represents a P. The range of P is the same with the range of a 32-bits unsigned integer (0 - 4294967295). Output Format You need to output the SBN prime number of each P in decimal form and exactly in a line. If you cannot find out any SBN prime number of P, please output 0 in a line. Sample Input: 10 3 1024 5998 Sample Output: 5 3 2 5981