title: Summation of a number made up of 4 5 6
body: <p>We are given three integers x, y and z. You have to find the sum of all numbers whose digits are made of only 4, 5 and 6, that have at most x fours in decimal representation, at most y fives in decimal representation and at most z sixes in decimal representation</p>
  
  <p>I am using the concept <a href="https://math.stackexchange.com/questions/479723/find-the-sum-of-all-4-digit-numbers-formed-by-using-digits-0-2-3-5-and-8">Describe Here</a></p>
  
  <p>My code:</p>
  
  <pre><code>// fact[i] is i!
      for(int i=0;i&lt;=x;i++)
          for(int j=0;j&lt;=y;j++)
              for(int k=0;k&lt;=z;k++){
  
             int t = i+j+k;
             if(t==0) continue;
             long ways = fact[t-1];
             long pow = (long) Math.pow(10,t-1);
             long rep=0;
             if(i!=0){
                 rep = fact[j]*fact[k];
                 if(i&gt;0) rep*=fact[i-1];
  
                o+= 4*pow*(ways/rep); 
             }
  
             if(j!=0){
                 rep = fact[i]*fact[k];
                 if(j&gt;0) rep*=fact[j-1];
  
                o+= 5*pow*(ways/rep); 
             }
  
             if(k!=0){
                 rep = fact[i]*fact[j];
                 if(k&gt;0) rep*=fact[k-1];
  
                o+= 6*pow*(ways/rep); 
             }
  
          }
  </code></pre>
  
  <p>But I am getting the wrong answer for <code>x=1 , y=1 and z=1</code> i am getting <code>3315</code> while the correct answer is <code>3675</code>.</p>
  
  <p>Please help me find my mistake.</p>
  
  <pre><code>4+5+6+45+54+56+65+46+64+456+465+546+564+645+654=3675
  </code></pre>