public long[] solve(int[] X, int[] Y, int[] Z) {
        long[] result = new long[X.length];
        for (int i = 0; i < Z.length; i++) {
            double x = X[i];
            double y = Y[i];
            double z = Z[i];

            System.out.println(String.format("[%d]---%f-%f-%f", i, x,y,z));

            if (y>x || y==x) {
                result[i]=0;
                continue;
            }
            
            double day = 1;
            double previous = 0;
            double lastJump = 1;

            double temp = 0;
            while (day<=z) {
                previous = day;
                if (day*(x-y)/y<lastJump) {
                    day = Math.ceil((lastJump*y)/(x-y));
                    if ((day-previous) % lastJump!=0) {
                        day += lastJump - ((day-previous) % lastJump);
                    }
                    if (day>z) {
                        day = z - ((z - previous) % lastJump);
                    }
                    //System.out.println(String.format("[Jump]Day: %1.1f|%1.1f|%1.1f", day, previous, lastJump));
                    if (day == previous) break;
                } else {
                    day = whatsNext(day, x, y);
                    lastJump = day - previous;
                    if (lastJump!=temp) {
                        //System.out.println(String.format("[Step]Day: %1.1f|%1.1f|%1.1f", day, previous, lastJump));
                        temp = lastJump;
                    }
                }
            }
            System.out.println(String.format("Final: %1.1f", previous));
//            result[i] = (long)((previous*x % y) + ((z-previous)*x));
            BigDecimal finalMoney = BigDecimal.valueOf((long)previous);
            finalMoney = finalMoney.multiply(BigDecimal.valueOf((long)x));
            finalMoney = finalMoney.remainder(BigDecimal.valueOf((long)y));
            BigDecimal t = BigDecimal.valueOf((long)z);
            t = t.subtract(BigDecimal.valueOf((long)previous));
            t = t.multiply(BigDecimal.valueOf((long)x));
            finalMoney = finalMoney.add(t);
            result[i] = finalMoney.longValue(); 
            System.out.println(String.format("Result: %d", result[i]));
        }
        return result;
    }