[Swift] LeetCode1175 prime arranged |. Prime Arrangements

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: to dare (WeiGanTechnologies)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: //www.cnblogs. com / strengthen / p / 11443474.html 
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.)

(Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive integers both smaller than it.)

Since the answer may be large, return the answer modulo 10^9 + 7.

 

Example 1:

Input: n = 5
Output: 12
Explanation: For example [1,2,5,4,3] is a valid permutation, but [5,2,3,4,1] is not because the prime number 5 is at index 1.

Example 2:

Input: n = 100
Output: 682289015

 

Constraints:

  • 1 <= n <= 100

 

Would you please give from  1 the  n number of program design aligned so that all the "prime number" should be placed in "prime index" on (the index starts at 1); you need to return the total number of possible solutions.

Let's take a look at "prime": prime number must be greater than 1, and can not be less than the product of its two positive integers to represent.

Since the answer may be very large, so please return the answer mode mod  10^9 + 7 after the results can be.

 

Example 1:

Input: n = 5 
Output: 12 
Explanation: for example, [1,2,5,4,3] is an effective arrangement, but [5,2,3,4,1] is not, as in the second 5 in the case where a prime number is incorrectly placed in a position on the index.

Example 2:

Input: n = 100 
Output: 682 289 015

 

prompt:

  • 1 <= n <= 100

Guess you like

Origin www.cnblogs.com/strengthen/p/11443474.html