Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.2 kB
6
Indexable
class MyThread extends Thread {

    int start;
    int end;
    int partialLargestDivisor=0,numberOfdivisors=0;

    MyThread(int start, int end) {
        this.start = start;
        this.end = end;
    }

    public void run() {
        for (int i = start; i <= end; i++) {
            int divisorcounter=0;
            for(long j=1; j<=i;j++){
                if(i%j==0){
                    divisorcounter++;
                }
            }
            if(numberOfdivisors<divisorcounter){
                partialLargestDivisor=i;
                numberOfdivisors=divisorcounter;
            }
        }
        if(numberOfdivisors>Class.numberofDivisors){
            Class.numberofDivisors=numberOfdivisors;
            Class.greatestDivisor=partialLargestDivisor;
        }
    }
}

public class Class{
    public static int greatestDivisor,numberofDivisors;
    public static void main(String[] args) {

        MyThread thread1 = new MyThread(1, 10000);
        MyThread thread2 = new MyThread(10001, 20000);
        MyThread thread3 = new MyThread(20001, 30000);
        MyThread thread4 = new MyThread(30001, 40000);
        MyThread thread5 = new MyThread(40001, 50000);
        MyThread thread6 = new MyThread(50001, 60000);
        MyThread thread7 = new MyThread(60001, 70000);
        MyThread thread8 = new MyThread(70001, 80000);
        MyThread thread9 = new MyThread(80001, 90000);
        MyThread thread10 = new MyThread(90001, 100000);
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();
        thread6.start();
        thread7.start();
        thread8.start();
        thread9.start();
        thread10.start();
        try{
            thread1.join();
            thread2.join();
            thread3.join();
            thread4.join();
            thread5.join();
            thread6.join();
            thread7.join();
            thread8.join();
            thread9.join();
            thread10.join();
        }
        catch(Exception e){
            System.out.println(" ");
        }
        System.out.println("Greatest Divios: "+greatestDivisor);
    }
}
Leave a Comment