1357.cpp

来自「哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码」· C++ 代码 · 共 39 行

CPP
39
字号
/*  This Code is Submitted by wywcgs for Problem 1357 on 2006-01-12 at 03:06:45 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 10240;
const int LIMIT = 102400;
const double eps = 1e-4;

int main()
{
	int p[MAX], pn = 0;
	bool prime[LIMIT];
	int i, j;
	int m, a, b;
	
	
	memset(prime, true, sizeof(prime));
	for(i = 2; i < LIMIT; i++)
		if(prime[i]) {
			p[pn++] = i;
			for(j = 2; i*j < LIMIT; j++) prime[i*j] = false;
		}
	while(scanf("%d %d %d", &m, &a, &b) != EOF && m != 0) {
		int l = (int)(sqrt((double)m)+eps);
		int d = upper_bound(p, p+pn, l) - p;
		int w = 0, h = 0;
		for(i = 0; i < d; i++) {
			int u = min(p[i]*b/a, m/p[i]);
			int uo = upper_bound(p, p+pn, u) - p - 1;
			if(p[i]*p[uo] > w*h) w = p[i], h = p[uo];
		}
		printf("%d %d\n", w, h);
	}

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?