#include using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() typedef long long ll; typedef vector vi; typedef vector vl; const ll INF = 1e18; const ll MOD = 1e9 + 7; template T chmax(T& a, const T& b){return a = (a > b ? a : b);} template T chmin(T& a, const T& b){return a = (a < b ? a : b);} // #define DEBUG_MODE #ifdef DEBUG_MODE #define dump(x) cout << #x << " : " << x << " " #define dumpL(x) cout << #x << " : " << x << '\n' #define LINE cout << "line : " << __LINE__ << " " #define LINEL cout << "line : " << __LINE__ << '\n' #define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " " #define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl #define STOP assert(false) #else #define dump(x) #define dumpL(x) #define LINE #define LINEL #define dumpV(v) #define dumpVL(v) #define STOP assert(false) #endif #define mp make_pair namespace std { template ostream &operator <<(ostream& out, const pair& a) { out << '(' << a.fi << ", " << a.se << ')'; return out; } } struct Sieve { vector primes; vector _isPrime; Sieve(int n) : _isPrime(n+1, 1) { buildPrimes(); } void buildPrimes() { _isPrime[0] = _isPrime[1] = 0; int n = _isPrime.size(); REP(i, 2, n) { if(_isPrime[i]) { primes.push_back(i); for(int j = i+i; j < n; j += i) _isPrime[j] = false; } } } bool isPrime(int i) { return _isPrime[i]; } }; int main(){ ll m, n; cin >> m >> n; vl c(n); rep(i, n) cin >> c[i]; vl dp(m+1, 0LL); for(auto&& x: c) if(x < (int)dp.size()) dp[x] = 1; rep(i, n) { rep(j, dp.size() - c[i]) if(dp[j] > 0) { chmax(dp[j+c[i]], dp[j]+1); } } Sieve sieve(m); ll ans = *max_element(all(dp)); rep(i, m) if(sieve.isPrime(m - i)) { ans += dp[i]; dump(i);dumpL(dp[i]); } cout << ans << '\n'; dumpL(dp[m]); return 0; }