public class DefinisiFormal {

    public static void main(String[] args) {
        // f(n) = 3n^2 + 20n + 7   ->   g(n) = n^2 dengan konstanta c = 4
        int c = 4;
        int batasAtas = 100_000;

        // Cari n0 terkecil sejak mana f(n) <= c * g(n) mulai berlaku.
        int n0 = -1;
        for (int n = 1; n <= batasAtas; n++) {
            if (f(n) <= c * g(n)) {
                n0 = n;
                break;
            }
        }

        // Pastikan pertidaksamaan tetap berlaku untuk semua n >= n0.
        boolean tetapBerlaku = true;
        for (int n = n0; n <= batasAtas; n++) {
            if (f(n) > c * g(n)) {
                tetapBerlaku = false;
                break;
            }
        }

        System.out.println("f(n) = 3n^2 + 20n + 7   g(n) = n^2   c = " + c);
        System.out.println("n0 terkecil yang memenuhi f(n) <= c*g(n): " + n0);
        System.out.println("Diverifikasi tetap berlaku sampai n=" + batasAtas
                + ": " + (tetapBerlaku ? "ya" : "tidak"));
    }

    static long f(int n) {
        return 3L * n * n + 20L * n + 7;
    }

    static long g(int n) {
        return 1L * n * n;
    }
}
