#include #define rep(i,a,b) for(int i=int(a);i> M >> N; vector V(N); rep(i,0,N)cin >> V[i]; int table[M+1] = {1,1};//0が素数 for(int i = 2;i <= M;i++){ if(table[i])continue; for(int j = i * 2;j <= M;j += i){ table[j] = 1; } } int dp[N+1][M+1] = {}; dp[0][0] = 1; rep(i,0,N){ rep(j,0,M+1)dp[i+1][j] = dp[i][j]; rep(j,V[i],M+1){ if(!dp[i+1][j - V[i]])continue; dp[i+1][j] = max(dp[i+1][j], dp[i+1][j - V[i]] + 1); } } rep(i,0,M+1)dp[N][i] = max(0, dp[N][i] - 1); //arep(i,0,M+1)cout << dp[N][i] << " \n"[i==M]; ll cnt = 0; rep(i,1,M+1){ if(dp[N][M - i] && !table[i]){ //cout << i << endl; cnt += dp[N][M - i]; dp[N][M - i] = 0; } } int maxi = 0; rep(i,0,M+1)maxi = max(maxi, dp[N][i]); cout << cnt + maxi << endl; }