标签:style blog class code java ext
这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来。
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 5 char isPrime[100001]; 6 7 int main() { 8 int i, j, q, p, maxi, maxj, max; 9 double m, a, b, n, tmp1, tmp2; 10 11 memset(isPrime, 1, sizeof(isPrime)); 12 isPrime[0] = isPrime[1] = 0; 13 for (i=2; i<100001; ++i) { 14 if (isPrime[i]) { 15 for (j=i+i; j<100001; j+=i) 16 isPrime[j] = 0; 17 } 18 } 19 20 while (scanf("%lf %lf %lf", &m, &a, &b) != EOF) { 21 if (m==0.0f && a==0.0f && b==0.0f) 22 break; 23 n = a/b; 24 a = sqrt(m); 25 b = sqrt(m/n); 26 i = (int)floor(a); 27 j = (int)floor(b); 28 max = 0; 29 for (p=j; p>=2; --p) { 30 if ( !isPrime[p] ) 31 continue; 32 if (p*i <= max) 33 break; 34 for (q=i; q>=2; --q) { 35 if ( !isPrime[q] ) 36 continue; 37 tmp1 = p*q; 38 tmp2 = q*1.0f/p; 39 if (tmp1<=m && tmp2<=1 && tmp2>=n) { 40 if (tmp1 > max) { 41 max = tmp1; 42 maxj = p; 43 maxi = q; 44 } 45 break; 46 } 47 } 48 } 49 printf("%d %d\n", maxi, maxj); 50 } 51 52 return 0; 53 }
【HDOJ】1239 Calling Extraterrestrial Intelligence Again,布布扣,bubuko.com
【HDOJ】1239 Calling Extraterrestrial Intelligence Again
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/bombe1013/p/3716440.html