All problems

Problem 859

Prime Arrangements

Easy · 10 pts · Math, Combinatorics

Problem

Count the permutations of the numbers 1 to N in which every prime number sits at a prime position (positions are numbered from 1). Print the count modulo 1000000007. The primes can be arranged among the prime positions in any order, and the other numbers among the other positions, so with P primes up to N the answer is P! × (N - P)!. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).

Input

A single integer N.

Output

Print the number of valid permutations modulo 1000000007.

Constraints

1 <= N <= 100

Example input

5

Example output

12

Explanation

For N = 5 the primes 2, 3 and 5 must use positions 2, 3 and 5 (3! = 6 ways), and 1 and 4 use positions 1 and 4 (2! = 2 ways). That gives 12 permutations.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Sum of Square Numbers Next: Number of Common Factors