|
|
back to board#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; } } } 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). I'm doing exactly that but I keep getting WA. Could you give me some sample inputs/outputs? |
|
|