1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #406 (Prime Cuts)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=347&mosmsg=Submission+received+with+ID+7037006
*
* @author Christoph Miesel
* @author Andre Wolfram
* @author Robert Seilbeck
* @version 1.0, 03/25/2009
*
* Status : Accepted
* Runtime 1.130
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

private static boolean isPrim(int num) {
if (num % 2 == 0) {
return false;
}
for (int i = 3; i < num; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}

public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line;
ArrayList<Integer> allPrims = new ArrayList<Integer>();
allPrims.add(1);
allPrims.add(2);

// Berechnet alle Primzahlen bis 1000. Erspart die Berechnung der Primzahlen jedes Wertes.
for (int num = 2; num <= 1000; num++) {
if (isPrim(num)) {
allPrims.add(num);
}
}
int[] primArray = new int[allPrims.size()];
for (int i = 0; i < allPrims.size(); i++) {
primArray[i] = allPrims.get(i);
}
int upperBound = 0;

// Schleife über jeden einegebenen Wertebereich
while ((line = reader.readLine()) != null) {
String[] tmp = line.split(" ");
upperBound = Integer.parseInt(tmp[0]);
int rangeAroundCenter = Integer.parseInt(tmp[1]);

// Sucht den Index der höchsten Primzahl welche kleiner oder gleich
// des eingegebenen Wertes ist
int primIndex = -1;
for (int i = primArray.length - 1; i >= 0; i--) {
if (primArray[i] <= upperBound) {
primIndex = i;
break;
}
}

//Ausgabe
System.out.print(upperBound + " " + rangeAroundCenter + ":");
int center = new Double(primIndex / 2).intValue();
if (primIndex >= rangeAroundCenter * 2) {
if ((primIndex + 1) % 2 == 0) {
printSubList(center - rangeAroundCenter + 1, center
+ rangeAroundCenter, primArray);

} else {

rangeAroundCenter--;
printSubList(center - rangeAroundCenter, center
+ rangeAroundCenter, primArray);

}
} else {
printSubList(0, primIndex, primArray);
}

System.out.println();
System.out.println();
}

}

public static void printSubList(int lowerBound, int upperBound, int[] a) {
String out = "";
for (; lowerBound <= upperBound; lowerBound++) {
out = out + " " + a[lowerBound];
}
System.out.print(out);
}

}