首页 > 代码库 > minlen of expression of integer

minlen of expression of integer

given an integer ,find 最小长度minlen 的expression of integer, minlen 定义为多少个完全平方数相加
例如 14 = 1 + 4 + 9, minlen = 3

int MinExpressionInteger(int i){    int k = sqrt(i);    if (k*k == i)        return 1;    int minLen = INT_MAX;    while (k > sqrt(i / 2) - 1)    {        int len = 1 + MinExpressionInteger(i - k*k);        if (minLen > len)            minLen = len;        k--;    }    return minLen;}

  

minlen of expression of integer