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

"i got Ac use 0.02s" i used this solution but in JAVA
Posted by KUM 25 Mar 2008 18:18
public static void main(String[] args){
        Scanner in = new Scanner(System.in);
    int k,ans=0,start,stop;
    double r;
    boolean p;

    start=in.nextInt();
    stop=in.nextInt();
    r=2147483647;
    if (start==1) System.out.println(1); else {

        for (int i=stop; i>=start; i-- ){
            p=true;
            for (int j=2; j<=Math.round(Math.sqrt(i)); j++) {
                if ((i % j)==0) {
                    p=false;
                    break;
                }
            }
            if (p) {
                ans=i;
                r=1/i;
                break;
            }
        }

        for (int i=stop; i>=start; i--){
            if (Math.abs(Math.sqrt(i)-Math.round(Math.sqrt(i)))<(1e-8)) {
                if (r>(1+Math.sqrt(i))/i)  ans=i;
                break;
            }
        }
        if (ans!=0) {
            System.out.println(ans);
        } else {
            for (int i=start; i<=stop; i++){
                k=1;
                for (int j=2; j<=Math.round(Math.sqrt(i)); j++) {
                    if ((i % j)==0) {
                        k+=(j+(i / j));
                        if (j==(i / j))  k-=j;
                    }
                    if (r>(k/i)) {
                        ans=i;
                        r=k/i;
                    }
                }

            }
            System.out.println(ans);
        }
    }
    }


Where is my mistake&

Edited by author 25.03.2008 18:19
No subject
Posted by Meni Packeou 17 Aug 2008 23:04


Edited by author 18.08.2008 14:34
Re: "i got Ac use 0.02s" i used this solution but in JAVA
Posted by Meni Packeou 18 Aug 2008 14:33