#include using namespace std; unsigned long moves_for_stick_of_length(unsigned long N) { //cout << "Considering stick of length " << N << endl; //cout << "Getting primes" << endl; vector primes; unsigned long divisor = 2; unsigned long N_orig = N; if (N == 1) { primes.push_back(1); unsigned long moves = 1; //cout << "Number of moves for this chocolate stick: " << moves << endl; return moves; } else { while(true) { if (N == divisor) { primes.push_back(divisor); //cout << "found last prime " << divisor << endl; break; } else if ((N%divisor) == 0) { primes.push_back(divisor); //cout << "found prime " << divisor << endl; N /= divisor; //cout << "N is now " << N << endl; } else { if (divisor*divisor > N) { divisor = N; } else { divisor++; } //cout << "incrementing divisor" << endl; } } } /* cout << "Primes: "; for (int ii=0; ii primes_sorted(primes.size()); for (int ii=0; ii a) { // Return the length of the longest possible sequence of moves. int n = a.size(); unsigned long total_moves = 0; for (int original_sticks=0; original_sticks> n; vector a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } unsigned long result = longestSequence(a); cout << result << endl; return 0; }