Project Euler #116: Red, green or blue tiles

  • + 0 comments

    Can any one help me. My code :-

    import java.io.*;
    import java.util.*;
    
    
    
    public class Solution {
        static int getTilesProbablity(int tiles){
            System.out.println("in tiles");
            int red = 2;
            int green = 3;
            int blue = 4;
            int psb = 0;
            psb += get(red, tiles);
         //    System.out.println("psb :"+psb);
            psb += get(green, tiles);
          //   System.out.println("psb :" + psb);
            psb += get(blue, tiles);
           //  System.out.println("psb :" + psb);
            return psb;
        }
        static int get(int n, int tiles){
            int count = 0,ic = n;
          //  System.out.println("in get");
           
            for( int i = 0 ; i < tiles ; i++){
            //    System.out.println("i :"+i);
                for(int j = 0; j < tiles ; j++){
              //     System.out.println("j :"+j);
                    if((tiles - j - ic) >= 0){// j = 2 ; 5 - 2 = 3 
                //         System.out.println("tiles :" + tiles);
                  //      System.out.println("Ic : " + ic);
                    //    System.out.println("n : " + n);
     
                        count ++;
                   // System.out.println("coutn :" + count);
                    }
                }
                ic += n;
            }
            return count;
        }
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int i = sc.nextInt();
            System.out.println(i);
            for( int qi = 0 ; qi < i ; qi++){
                System.out.println(getTilesProbablity(sc.nextInt()));
            }
        }
    }
    

    Now to gives 11 of 12 and I know the 6 case of red is not counting this is very simple code I dont want working code but Can i have a good tutorial link for @gosh_saikat4000 comment :: "Look up matrix exponentiation. Learn how to find the n-th term of a linear recurrence in O(log n) time. ":: or any suggestion to modify my code? thanks waiting...