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 have seen the ac pro of pas,but i use c++ but can't got AC,any master can help me ?
Posted by kkgz 21 Apr 2004 08:50
#include<iostream.h>
#include<math.h>
#include<limits.h>
main()
{
    long D,U,i,sum,crno,minN,j;
    double min,ratio,nouse;
    int flag=0;
    cin>>D>>U;
    min=1000000;
    minN=D;
    for(long t=1000000;t>=2;t--)
    {
        U=t;
    if(D==1)
        cout<<'0';
    else
    {
        for(i=U;i>=D;i--)
        {
            sum=1;

            for(j=2;j<=sqrt((double)i);j++)
            {
                if(i%j==0)
                {
                    sum+=j+i/j;
                }
            }
            if(i%(j-1)==0)
                sum-=j;

            ratio=double(sum)/(double)i;
            if(ratio<=min)
            {

                min=ratio;
                minN=i;
                if(sum==1)
                {
                    for(long k=U;k>=D;k--)
                    {

                        if(modf(sqrt((double)k),&nouse)==0)
                        {
                            ratio=(1+sqrt((double)k))/(double)k;
                            if(ratio>min)
                                break;
                            else
                            {

                                min=k;
                                minN=k;
                                break;
                            }
                        }
                    }
                    break;
                }

            }
        }
        cout<<minN;
    }
    }
}
Re: i have seen the ac pro of pas,but i use c++ but can't got AC,any master can help me ?
Posted by Gheorghe Stefan 22 Apr 2004 16:57
if there are prime numbers in the interval you should print it. Else, if there are not primes in the interval, it is quite small and you can brute search the number. If the first bound of the interval is 1 you must print 1 (I got many WAs not knowing this).
Re: i have seen the ac pro of pas,but i use c++ but can't got AC,any master can help me ?
Posted by Evil Cheater 28 Apr 2004 09:51
I'm doing exactly that but I keep getting WA. Could you give me some sample inputs/outputs?