• + 0 comments

    Simple Java Code

    class Result {
    
        /*
         * Complete the 'viralAdvertising' function below.
         *
         * The function is expected to return an INTEGER.
         * The function accepts INTEGER n as parameter.
         */
    
        public static int viralAdvertising(int n) {
        // Write your code here
            
           int total = 0;
           int recip = 5;
           
           for(int i = 1; i<= n; i++)
           {
            int div = recip / 2;
            total+=div;
            int mul = div * 3;
            recip = mul;
           }
           return total;
        }
    
    }