#include <stdio.h>
#define MAX 10000
int ver[MAX+3]={0};
int primes[MAX+3];
int gen() {
int i, j, k=0;
for (i=2 ; i<=MAX ; i++) {
if (!ver[i]) {
primes[k++]=i;
for (j=2 ; i*j<=MAX ; j++) {
ver[i*j]=1;
}
}
}
return k;
}
int main() {
int q=gen(), high, low, t, p, i, x, n, max, res;
scanf("%d",&t);
while (t--) {
max = -1;
res = -1;
scanf("%d",&n);
for (i=0 ; i<q && primes[i]<=n ; i++) {
x = primes[i];
low = (n-x)/x;
high = n/x;
for (p=low ; p<=high ; p++) {
if (max<(n-p*x)) {
max = n-p*x;
res = x;
}
}
}
printf("%d\n",res);
}
return 0;
}
Monday, October 18, 2010
[UVa] 10852 - Less Prime
My solution simply simulates what is described in the problem, but if you wanna know how to shorten this code then there is one thing to know, you're looking for x for maximum n%x.
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Install MinGW GCC Port on Windows. 1. Just go to this address [ http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ ]...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.