【HDOJ】1239 Calling Extraterrestrial Intelligence Again
2014-05-08 16:16
344 查看
这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来。
#include <stdio.h> #include <string.h> #include <math.h> char isPrime[100001]; int main() { int i, j, q, p, maxi, maxj, max; double m, a, b, n, tmp1, tmp2; memset(isPrime, 1, sizeof(isPrime)); isPrime[0] = isPrime[1] = 0; for (i=2; i<100001; ++i) { if (isPrime[i]) { for (j=i+i; j<100001; j+=i) isPrime[j] = 0; } } while (scanf("%lf %lf %lf", &m, &a, &b) != EOF) { if (m==0.0f && a==0.0f && b==0.0f) break; n = a/b; a = sqrt(m); b = sqrt(m/n); i = (int)floor(a); j = (int)floor(b); max = 0; for (p=j; p>=2; --p) { if ( !isPrime[p] ) continue; if (p*i <= max) break; for (q=i; q>=2; --q) { if ( !isPrime[q] ) continue; tmp1 = p*q; tmp2 = q*1.0f/p; if (tmp1<=m && tmp2<=1 && tmp2>=n) { if (tmp1 > max) { max = tmp1; maxj = p; maxi = q; } break; } } } printf("%d %d\n", maxi, maxj); } return 0; }
相关文章推荐
- HDOJ 1239:Calling Extraterrestrial Intelligence Again 解题报告
- POJ-1411 & HDOJ-1239 Calling Extraterrestrial Intelligence Again 解题报告
- hdoj 1239 Calling Extraterrestrial Intelligence Again
- hdoj 1239 Calling Extraterrestrial Intelligence Again(找质数对)
- 【HDU】 1239 Calling Extraterrestrial Intelligence Again
- HDU 1239 Calling Extraterrestrial Intelligence Again(找素数)
- hdu 1239 Calling Extraterrestrial Intelligence Again(数学题)
- HDU 1239 Calling Extraterrestrial Intelligence Again
- HDU 1239 Calling Extraterrestrial Intelligence Again(找素数)
- HDU 1239 Calling Extraterrestrial Intelligence Again 【打表+暴力搜索】
- HDU 1239 Calling Extraterrestrial Intelligence Again (素数)
- hdu 1239 Calling Extraterrestrial Intelligence Again
- Hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)
- HDU 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- hdu 1239 Calling Extraterrestrial Intelligence Again
- 【搜索剪枝】HOJ 1239 Calling Extraterrestrial Intelligence Again
- hdu1239 Calling Extraterrestrial Intelligence Again (小组赛C) 素数对