Problem Description A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted of 1679 bits and was meant to be translated to a rectangular picture with 23 * 73 pixels. Since both 23 and 73 are prime numbers, 23 * 73 is the unique possible size of the translated rectangular picture each edge of which is longer than 1 pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic. Input The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicated the end of the input and should not be treated as data to be processed. Output The output is a sequence of pairs of positive integers. The i-th output pair corresponds to the i-th input triplet. The integers of each output pair are the width p and the height q described above, in this order. Sample Input 5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0 Sample Output 2 2 313 313 23 73 43 43 37 53 Source |
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int prime[10010]={0};
int inv[10010];
int d=0;
void Prime(){
for(int i=2;i<=10000;i++){
if(prime[i]==0){
for(int j=i+i;j<=10000;j+=i){
prime[j]=1;
}
inv[d++]=i;
}
}
}
int main(){
Prime();
int m,a,b;
while(scanf("%d %d %d",&m,&a,&b)!=EOF && (m!=0 || a!=0 || b!=0)){
int p,q;
double x=1.0*a/b;
int l=0,r=0;
for(int i=0;i<d;i++){
if(inv[i]>=m){
break;
}
for(int j=i;j<d;j++){
double y=1.0*inv[i]/inv[j];
if(inv[i]*inv[j]>m || y<x){
break;
}
if(inv[i]*inv[j]>l*r){
l=inv[i];
r=inv[j];
}
}
}
printf("%d %d\n",l,r);
}
}