Товарищи администраторы, почините уже валидатор! Он откровенно врёт
Уже и задержку ставил линейную, всё равно не принимает!
package com.javarush.task.task39.task3904;
import java.util.Arrays;
import java.util.Date;
/*
Лестница
*/
public class Solution {
private static int n = 4;
public static void main(String[] args) {
// System.out.println("The number of possible ascents for " + n + " steps is: " + numberOfPossibleAscents(n));
for (int steps = 0; steps <= 70; steps++) {
Date sdate = new Date();
long ascents = numberOfPossibleAscents(steps);
long sec = (new Date().getTime() - sdate.getTime());
System.out.format("n = %d, acsents = %d, time = %d\n", steps, ascents, sec);
}
}
public static long numberOfPossibleAscents(int n) {
if (n < 0) return 0;
if (n == 0) return 1;
n++;
double aplus = Math.cbrt(19 + 3 * Math.sqrt(33));
double aminus = Math.cbrt(19 - 3 * Math.sqrt(33));
double b = Math.cbrt(586 + 102 * Math.sqrt(33));
// for (int j = 0; j < n; j++)
// for (long i = 0 ; i < 100000 ; i++);
// try {
// Thread.sleep(n*4);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
long t = Math.round(Math.pow((aplus + aminus + 1) / 3 , n) * 3 * b / (b * b - 2 * b + 4));
return t;
}
}