1. 

/**

* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10

 * Problem: 406 Prime Cuts

* Link: http://uva.onlinejudge.org/external/4/406.pdf

*

 * @author Viktoriya Ryabova

* @version 1.0, 05/30/2010

*

 * Method : Ad-Hoc

* Status : Accepted

* Runtime: 2.132

*/

import java.util.Scanner;

 

public class Main {

 

      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);

            while (sc.hasNext()) {

 

                  int n = sc.nextInt();

                  int c = sc.nextInt();

                  // abbruchbedingung

                  if (n==0 || c==0)return;

                  int count = 0;

                  int printCount;

                  int limit;

                  int start;

                 

                  int[] primeNumbers = new int[n];

                  // alle primzahlen von 1 bis n in array hinzufügen

                  for (int i = 1; i <= n; i++) {

                        if (isPrime(i)) {

                             primeNumbers[count] = i;

                             count++;

                        }

                  }

                  //es wird gerechnet, wie viele primzahlen ausgegeben werden und genauer abschnitt

                  //des arrays, der ausgegeben wird

                  if (count % 2 == 0) {

                        printCount = c * 2;

                        if (count > printCount) {

                             start = (count / 2 - printCount / 2);

                             limit = (count - printCount) / 2 + printCount;

                        } else {

                             start = 0;

                             limit = count;

                        }

 

                  } else {

                        printCount = c * 2 - 1;

                        if (count > printCount) {

                             start = (count - printCount + 1) / 2;

                             limit = (count - printCount + 1) / 2 + printCount;

                        } else {

                             start = 0;

                             limit = count;

                        }

                  }

                  //Ausgabe des ergebnisses

                  System.out.print(n + " " + c + ": ");

                  for (int i = start; i < limit; i++) {

                        if (primeNumbers[i] != 0 && i!=(limit-1))

                             System.out.print(primeNumbers[i] + " ");

                        else System.out.print(primeNumbers[i]);

                  }

                  System.out.println("\n");

            }

      }

 

      // Prüfen ob die zahl eine primzagl ist

      public static boolean isPrime(int n) {

            if (n == 1) {

                  return true;

            } else if (n == 2) {

                  return true;

            } else if (n % 2 == 0) {

                  return false;

            } else {

                  for (int i = 3; i * i <= n; i += 2) {

                        if (n % i == 0) {

                             return false;

                        }

                  }

                  return true;

            }

      }

}