#include using namespace std; /* * game - finds the winning moves in the following game. You are given n * integers r1, ..., rn, and the object is to remove all the interior values * at minimum cost. The cost to remove any value ri is the gcd of r(i-1) and * r(i+1) */ const int SIZE = 100; struct tabentry { int cost; int k; int best; // only used for table[*][n-1] entries } table[SIZE][SIZE]; int vals[SIZE]; int gcd(int a, int b) { if(b==0) return a; else return gcd(b, a%b); } void output(int i, int j, int n) { if (j == 2) { cout << vals[i] << ',' << vals[(i+1)%n] << ',' << vals[(i+2)%n]; cout << ", cost = " << gcd(vals[i], vals[(i+2)%n]) << endl; } else if (j > 2){ int k = table[i][j].k; output(i, k, n); output((i+k)%n, j-k, n); cout << vals[i] << ' ' << vals[(i+k)%n] << ' ' << vals[(i+j)%n] << ", cost = " << gcd(vals[i], vals[(i+j)%n]) << endl; } } int main() { int n, icase=0; cin >> n; while (n > 0) { for(int i=0; i> vals[i]; } for(int i=0; i> n; } }