ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1118. Nontrivial Numbers

java solution (very simple)
Posted by rauf (coder) 30 May 2010 18:51
import java.util.Scanner;
public class problem1197 {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int I = in.nextInt();
        int J = in.nextInt();

        if (I == 1) {
            System.out.println(1);
            return;
        }
        if (I == J) {
            System.out.println(I);
            return;
        }
        int deyer[] = new int[100001];
        int idx = 0;
        int min = 10000;
        int mineded = 0;

        for (int i = J; i >= I; i--) {

            for (int j = i / 2; j >= 1; j--) {

                if (i % j == 0) {
                    if (j < min) {
                        min = j;
                        mineded = i;
                        if (j == 1) {
                            System.out.println(i);
                            return;
                        }
                    }

                    break;
                }
            }
        }
        System.out.println(mineded);

    }
}
Re: java solution (very simple)
Posted by Mamuka Sakhelashvili [Freeuni] 29 Dec 2013 02:05
Very interesting idea but I can't guess why is it always true. Can you give me some explanation on my mail please?! mamuka_sakhelashvili@yahoo.com
Thanks!