Description

Suppose you have n integers from 1 to n. A permutation perm is beautiful if for every i: perm[i] is divisible by i, or i is divisible by perm[i]. Return the number of beautiful arrangements.

Examples

Input:n = 2
Output:2
Explanation:

[1,2] and [2,1] are both beautiful.

Input:n = 1
Output:1
Explanation:

With n = 1, there's only one permutation [1]. Since 1 is divisible by 1, this arrangement is beautiful.

Input:n = 4
Output:8
Explanation:

The 8 beautiful arrangements are: [2,1,4,3], [3,2,1,4], [4,1,2,3], [2,4,1,3], [3,4,1,2], [4,2,1,3], [1,2,3,4], [1,4,3,2]. In each, every position i has perm[i] divisible by i or i divisible by perm[i].

Constraints

  • 1 ≤ n ≤ 15

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!