#include #define ll long long using namespace std; #define MAX 1000008 vector SieveOfEratosthenes(int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { // Update all multiples of p for (int i=p*2; i<=n; i += p) prime[i] = false; } } vector pr; for(int i=2;i<=n;i++){ if(prime[i]) pr.push_back(i); } return pr; } ll longestSequence(vector a) { // Return the length of the longest possible sequence of moves. vector pr=SieveOfEratosthenes(MAX); ll ans=0; for(int e=0;e> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } ll result = longestSequence(a); cout << result << endl; return 0; }