Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long
- #define ull unsigned long long
- #define nl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define rall(s) s.rbegin(), s.rend()
- #define getline(s) getline(cin>>ws,s)
- #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define pi 3.141592653589793
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- // freopen("filename.in", "r", stdin);
- // freopen("filename.txt", "w", stdout);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
- int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- vector<ll> v;
- // prime check
- bool isPrime(ll n) {
- if (n <= 1 or (n%2==0 and n!=2)) return false;
- for(int i=3; i<=sqrt(n); i+=2) {
- if(n%i==0) return false;
- }
- return true;
- }
- ll rec(vector<vector<ll>>&dp,int idx =0,int cur =0){
- if(idx == sz(v)) return isPrime(cur);
- if(dp[idx][cur] != -1) return dp[idx][cur];
- return dp[idx][cur] = rec(dp,idx+1,cur) + rec(dp,idx+1,cur+v[idx]);
- }
- void solve(){
- ll n; cin>>n;
- v.assign(n,0);
- ll tot =0;
- for(int i=0;i<n;i++){
- cin>>v[i];
- tot+=v[i];
- }
- vector<vector<ll>> dp(n+1,vector<ll>(tot+1,-1));
- cout<<rec(dp)<<nl;
- }
- int main(){
- Fast_IO();
- int t =1;
- //cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement