summaryrefslogtreecommitdiff
path: root/java/somme.java
blob: c1da9d5704df5f09244dde1a98d84f055511634a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;

public class HelloWorld {
    private static boolean pari(int n) {
        return (n % 2) == 0;
    }

    private static int sequenza(int n, boolean pollatz, int tCollatz) {
        int m = ((pollatz) ? 5 : 3), tot = 1;

        while(n != 1) {
            n = (pari(n)) ? n/2 : n*m+1;

            tot++;

            if(tCollatz != -1 && tot > tCollatz)
                break;
        }

        return tot;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N1 = in.nextInt(), N2 = in.nextInt(), tot = 0, collatz;

        for(int i = N1; i <= N2; i++) {
            collatz = sequenza(i, false, -1);
            if(sequenza(i, true, collatz) < collatz )
                tot++;
        }

        System.out.println(tot);
    }
}