1 solutions
-
0
#include <iostream> #include <cstdio> using namespace std; bool isprime(int a){ if(a==1)return false; for(int i = 2; i * i <= a; i++) if(a % i == 0) return false; return true; } int n,k; int a[2005]; long long ans; void dfs(int m, int sum, int startx){ if(m == k){ if(isprime(sum)) ans++; return ; } for(int i = startx; i < n; i++) dfs(m + 1, sum + a[i], i + 1); return ; } int main(){ scanf("%d%d",&n,&k); for(int i = 0; i < n; i++) scanf("%d",&a[i]); dfs(0, 0, 0); printf("%lld\n",ans); return 0; }
- 1
Information
- ID
- 6701
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- (None)
- # Submissions
- 92
- Accepted
- 14
- Uploaded By