洛谷p1036python
时间: 2023-11-17 17:01:54 浏览: 104
洛谷P1002 过河卒题解
5星 · 资源好评率100%
很抱歉,根据提供的引用内容中没有关于洛谷p1036的Python代码。但是,根据引用和引用中的C++代码,可以将其转换为Python代码。您可以参考以下Python代码实现洛谷p1036的功能:
```python
def isPrime(i):
if i == 2:
return True
for j in range(2, int(i ** 0.5) + 1):
if i % j == 0:
return False
return True
def dfs(start, count, sum):
global ans
if count == k and isPrime(sum):
ans += 1
for i in range(start, n + 1):
dfs(i + 1, count + 1, sum + sz[i])
n, k = map(int, input().split())
sz = list(map(int, input().split()))
ans = 0
dfs(1, 0, 0)
print(ans)
```
```python
def isPrime(x):
if x == 2:
return True
for i in range(2, int(x ** 0.5) + 1):
if x % i == 0:
return False
return True
def cm(k_desc, already_sum, begin, end):
if k_desc == 0:
return isPrime(already_sum)
sum = 0
for i in range(begin, end + 1):
sum += cm(k_desc - 1, already_sum + x[i], i + 1, end)
return sum
n, k = map(int, input().split())
x = list(map(int, input().split()))
print(cm(k, 0, 0, n - 1))
```
阅读全文