//Dennis Matveyev for SER 2013 //Decimal #include #include #include #include using namespace std; //count up the digits in whole number int countWhole(int n) { int count = 0; while (n > 0) { n /= 10; count++; } if (count == 0) count++; //"0" still takes up 1 digit spot return count; } //returns notation lenth as per problem description //note when leading zeroes are involved in the period, we consider this: 0.(002323) and not this 0.00(232300) to be our length int getNotationLength(int a, int b) { int count = 0; //take care of the whole part count += countWhole(a / b); if (a >= b) a %= b; //take care of the dot if (a>0) count++; //take care of the decimal part vector used(b+1); //used to detect repeating decimal while (a>0 && !used[a]) { used[a] = 1; //division algo a *= 10; a %= b; count++; } if (used[a]) count += 2; //the parens return count; } int main() { int n; while (cin >> n && n > 0) { int max = 0; for (int b = 1; b <= n; b++) max = std::max(max, getNotationLength(1, b)); //trial&error say 1/b works out cout << max << endl; } return 0; }