Just Factor decomposition


  • 1
    C

    After thinking, I found that the problem is equivalent to Factor decomposition。
    For convenience,Copy(written in C,Paste(written in C)。CP just like multiplied by 2, CPP just like multiplied by 3. So we can find the law, CP[1,n] (represents how many Paste[s]) just like multiplied by [2, n+1].

    public int minSteps(int n) {
       int sum = 0;
       while(n>=2){
        for(int i=2;i<=n; i++){
            if(n % i == 0){
                sum += i;
                n = n/i;
                break;
             }
          }
      }
      return sum; }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.