Skip to content

Commit 1cf7984

Browse files
authoredFeb 21, 2025··
feat: update python3 solution to lc problem: No.2992 (#4091)
1 parent 7bfc65a commit 1cf7984

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed
 

‎solution/2900-2999/2992.Number of Self-Divisible Permutations/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Solution:
108108
return 1
109109
ans = 0
110110
for j in range(1, n + 1):
111-
if (mask >> j & 1) == 0 and (i % j == 0 or j % i == 0):
111+
if (mask >> j & 1) == 0 and gcd(i, j) == 1:
112112
ans += dfs(mask | 1 << j)
113113
return ans
114114

@@ -267,7 +267,7 @@ class Solution:
267267
for mask in range(1 << n):
268268
i = mask.bit_count()
269269
for j in range(1, n + 1):
270-
if (mask >> (j - 1) & 1) == 1 and (i % j == 0 or j % i == 0):
270+
if (mask >> (j - 1) & 1) == 1 and gcd(i, j) == 1:
271271
f[mask] += f[mask ^ (1 << (j - 1))]
272272
return f[-1]
273273
```

‎solution/2900-2999/2992.Number of Self-Divisible Permutations/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Solution:
106106
return 1
107107
ans = 0
108108
for j in range(1, n + 1):
109-
if (mask >> j & 1) == 0 and (i % j == 0 or j % i == 0):
109+
if (mask >> j & 1) == 0 and gcd(i, j) == 1:
110110
ans += dfs(mask | 1 << j)
111111
return ans
112112

@@ -265,7 +265,7 @@ class Solution:
265265
for mask in range(1 << n):
266266
i = mask.bit_count()
267267
for j in range(1, n + 1):
268-
if (mask >> (j - 1) & 1) == 1 and (i % j == 0 or j % i == 0):
268+
if (mask >> (j - 1) & 1) == 1 and gcd(i, j) == 1:
269269
f[mask] += f[mask ^ (1 << (j - 1))]
270270
return f[-1]
271271
```

‎solution/2900-2999/2992.Number of Self-Divisible Permutations/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def dfs(mask: int) -> int:
77
return 1
88
ans = 0
99
for j in range(1, n + 1):
10-
if (mask >> j & 1) == 0 and (i % j == 0 or j % i == 0):
10+
if (mask >> j & 1) == 0 and gcd(i, j) == 1:
1111
ans += dfs(mask | 1 << j)
1212
return ans
1313

‎solution/2900-2999/2992.Number of Self-Divisible Permutations/Solution2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ def selfDivisiblePermutationCount(self, n: int) -> int:
55
for mask in range(1 << n):
66
i = mask.bit_count()
77
for j in range(1, n + 1):
8-
if (mask >> (j - 1) & 1) == 1 and (i % j == 0 or j % i == 0):
8+
if (mask >> (j - 1) & 1) == 1 and gcd(i, j) == 1:
99
f[mask] += f[mask ^ (1 << (j - 1))]
1010
return f[-1]

0 commit comments

Comments
 (0)
Please sign in to comment.