#include using namespace std; std::map dc; void SieveOfEratosthenes(long n) /* Iterative Function to calculate (a^n)%p in O(logy) */ { // 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 (long 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 (long i=p*2; i<=n; i += p) prime[i] = false; } } // Print all prime numbers for (long p=2; p<=n; p++) if (prime[p]) dc.insert(std::make_pair(p, 1)); } bool isPrime(long n) { cout << "--" <::iterator it; it= dc.find(n); if(it != dc.end()) return it->second; for ( i = 2 ; i < long(sqrt(n))+1 ;i++) { long temp = 0; if (n % i == 0) { if (n/i == i) { long a = calc(i); //if(isPrime(i) == false) temp = a * i; //else //temp = a*1; } else { long a =1,b=1; //if(isPrime(n/i) == false) a = calc(n/i); //if(isPrime(i) == false) b = calc(i); temp = max(a*i,b*n/i); } } temp++; if (ma < temp) ma =temp; } //cout << "max for : " << n << " is : " << ma < mystack; while (n%2 == 0) { mystack.push(2); n = n/2; } // n must be odd at this point. So we can skip // one element (Note i = i +2) for (long i = 3; i <= sqrt(n); i = i+2) { // While i divides n, print i and divide n while (n%i == 0) { //printf("%d ", i); mystack.push(i); n = n/i; } } // This condition is to handle the case when n // is a prime number greater than 2 if (n > 2) { mystack.push(n); } // printf ("%d ", n); long sum =1; long inc = 1; while (!mystack.empty()) { //mystack.pop(); inc = inc *mystack.top(); // cout << "inc : " << inc < a) { // Return the length of the longest possible sequence of moves. long sum = 0; SieveOfEratosthenes((long(sqrt(1000000000000*1LL))+1)/2); //SieveOfSundaram(100000000); for(long i =0 ; i< a.size() ;i++) { //long temp = calc(a[i]); long temp = anup(a[i]); //cout << "max for a[i] : "<> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } long result = longestSequence(a); cout << result << endl; return 0; }