#include using namespace std; bool isPrime(int num) { if (num <= 3) { return num > 1; } else if (num % 2 == 0 || num % 3 == 0) { return false; } else { for (int i = 5; i * i <= num; i += 6) { if (num % i == 0 || num % (i + 2) == 0) { return false; } } return true; } } // function to print the divisors void findDivisors(long x, vector &v) { int i = 1; // This will loop from 1 to int(sqrt(x)) while(i*i <= x) { // Check if i divides x without leaving a remainder if(x % i == 0) { v.push_back(i); // Handle the case explained in the 4th if(x/i != i) { v.push_back(x/i); } } i++; } #if 0 // The vector will be printed in reverse cout << "PRINT\n"; for (int i=v.size()-1; i>=0; i--) printf("%d ", v[i]); printf("\n"); #endif } long breakStick(int a) { // cout << "a = " < v; findDivisors(a, v); //cout << "find devisor a = " << a << endl; for(int i =0; i < v.size(); i++) { if(v[i] == 1 || v[i] == a) continue; int devi = a/v[i]; //cout << "res = max(1 + " << v[i] << "*brkstick(" << devi << ")" << endl; res = max(res, 1+v[i]*breakStick(devi)); } return res; } long longestSequence(vector a) { // Return the length of the longest possible sequence of moves. int n = a.size(); int ans = 0; for(int i =0; i > n; #if 1 vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } long result = longestSequence(a); cout << result << endl; #else int res = breakStick(n); cout << res; #endif return 0; }