1.

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
* Angewandte Mathematik, SS11
* Problem: 10235 Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 29/3/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.376
*/

public class Main {

public static void main(String[] args) throws Exception{

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

String inputLine;

while((inputLine = reader.readLine()) != null){
int n = new Integer(inputLine);

if(!isPrime(n)){
System.out.println(n+" is not prime.");
} else if(!isEmirp(n)){
System.out.println(n+" is prime.");
} else {
System.out.println(n+" is emirp.");
}
}
}

private static boolean isPrime(int n){
if (n <= 1) return false;
for(int i = 2; i<n; i++){
if((n%i)==0) return false;
}
return true;
}

private static boolean isEmirp(int n){
int org = n;
int tmp = 0;
do{
tmp*=10;
tmp+=n%10;
}while((n/=10)!=0);
if(org == tmp) return false;
return isPrime(tmp);
}
}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 10235 Simply Empire
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176
*
* @author Benedikt Z®nnchen
* @author Erik Wenzel
* @version 1.0, 03/29/2011
*
* Method : Ad-hoc
* Status : Accepted
* Runtime: 0.884
*/

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main
{
private static Set<Integer> set = new HashSet<Integer>();

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number;
int swaped;

while(sc.hasNextInt())
{
number = sc.nextInt();
if(number == 1 || isPrime(number))
{
swaped = swap(number);
if(swaped!=number && isPrime(swaped))
{
System.out.println(number + " is emirp.");
}
else
{
System.out.println(number + " is prime.");
}
}
else
{
System.out.println(number + " is not prime.");
}
}
}

/**
* Dreht die zahl um zb: 1234 zu 4321
* @param n ganze Zahl
* @return n umgedreht
*/
public static int swap(int n)
{
int result = 0;
while(n!=0)
{
result *= 10;
result += n%10;
n /= 10;
}
return result;
}

// Euklid Algo
public static int ggT(int a, int b)
{
int r = -1;

while(r!=0)
{
r = a%b;
a = b;
b = r;
}

return a;
}

/**
* Bestimmt ob eine ganze Zahl eine Primzahl ist. (schleifen-l®sung)
* @param n ganze zahl
* @return true wenn n eine Primzahl ist, sonst false
*/
public static boolean isPrime(int n)
{
if(n == 2)
{
set.add(n);
return true;
}
else if(n < 2 || n%2==0)
{
return false;
}
else if(set.contains(n))
{
return true;
}
for(int i = 3; i <= Math.sqrt(n); i+=2)
{
if(n%i==0)
{
return false;
}
}
set.add(n);
return true;
}
}

3.

package sem2.am.simplyemirp;

/**
* Angewandte Mathematik, SS11
* Problem: 10235 - Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 04/10/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.832
*/

import java.util.*;

class Main {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();

// Abbruchschleife
if (n == 0)
break;

boolean found = false;

// zahl verdrehen
int neu = 0;
int restzahl = n;

for (int j = 0; j < 1000000; j++) {
int divr = restzahl % 10;
restzahl = restzahl / 10;
neu = neu + divr;
if (restzahl == 0 && divr == 0) {
neu = neu / 10;
break;
}
neu = neu * 10;
}

boolean foundn = false;
boolean foundneu = false;

// is emrip
if (prime(n)) {
foundn = true;
}
if (prime(neu) && neu != n) {
foundneu = true;
}
if (foundn && foundneu) {
System.out.println(n + " is emirp.");
found = true;
}

// is prime
if ((!foundneu && !found && foundn) || n == 1) {
System.out.println(n + " is prime.");
found = true;
}

// is nothing
if (!found && n != 1) {
System.out.println(n + " is not prime.");
}
}
}

// Entscheidet ob Zahl eine Primzahl
public static boolean prime(int n) {
if (n < 2)
return false;
if (n == 2)
return true;
if ((n % 2) == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2) // i = i+2
{
if (n % i == 0)
return false;
}
return true;
}
}

4.

/**
* FWP, Angewandte Mathematik, SS11
* Problem: 10235 - Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176 *
*
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-04-04 08:29:36
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.948
*/

import java.util.*;

public class Main
{
static HashSet<Integer> ErastoPrimes(int n)
{
boolean[] ausgesiebt = new boolean[n];
// es gibt 784980 primzahlen bis zu ner mille
HashSet<Integer> primSet = new HashSet<Integer>();
for(int i = 2; i < n ; i++)
{
ausgesiebt[i] = false; //vorbelegung mit "nicht ausgesiebt"
}
for(int i = 2; i < n; i++)
{
//wenn nicht ausgesiebt => primzahl => addTo ArrayList
if(ausgesiebt[i] == false)
{
primSet.add(i);
//alle vielfachen der vorher als primzahl erkannten zahl aussieben
for(int j = 2; i*j < n; j++)
{
ausgesiebt[i*j] = true;
}
}
}
return primSet;
}

public static void main(String[] args)
{
//Test DataSheet
/* StringBuilder sb = new StringBuilder("");
for(int i=6; i<=100000; i++)
{
sb = sb.append(i+(i%50 == 0? "\n": " "));
}
sb.append("0");
String s = sb.toString();
*/
HashSet<Integer> primzahlen = Main.ErastoPrimes(1000000);
Scanner scanner = new Scanner(System.in);
int zahl;
//while(zahl = scanner.nextInt() != 0
while(scanner.hasNext())
{
zahl = scanner.nextInt();
int exp = (int)Math.log10(zahl);
int reverse = 0;
int temp = zahl;
for(int i = exp; i >= 0; i--)
{
reverse += temp%10 * Math.pow(10, i);
temp = temp/10;
}
// System.out.println(reverse);
if(!primzahlen.contains(zahl))
{
System.out.println(zahl+" is not prime.");
}
else if(zahl != reverse && (primzahlen.contains(zahl) && primzahlen.contains(reverse)))
{
System.out.println(zahl+" is emirp.");
}
else
{
System.out.println(zahl+" is prime.");
}
}
}
}


---------------------------------------------------------------
1.

package emirp;
/**
* FWP, Ausgew√¤hlte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10235 Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=1176
*
* @author Patrick Bédat
* @version 1.0, 10/30/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.552
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{

public static void main(String... args) throws IOException
{
boolean[] sand = new boolean[1000000];
sieve(sand);

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

do
{
StringTokenizer st = new StringTokenizer(reader.readLine());
int n = Integer.parseInt(st.nextToken());

if(!sand[n])
{
int flipped = flip(n);
if(!sand[flipped] && n != flipped)
System.out.printf("%d is emirp.%n",n);
else
System.out.printf("%d is prime.%n",n);
}
else
System.out.printf("%d is not prime.%n",n);
}
while(reader.ready());
}

private static int flip(int n)
{
int flipped = 0;

int length = (int)Math.log10(n) + 1;
int currentBase = (int)Math.pow(10, length - 1);

for(int i = 0; i < length; i++)
{
int currentDigit = n % 10;
flipped += currentBase*currentDigit;
n -= currentDigit;
currentBase /= 10;
n/= 10;
}

return flipped;
}

private static void sieve(boolean[] sand)
{
for(int i = 2; i < sand.length; i++)
{
if(!sand[i])
for(int j = i << 2; j < sand.length; j+=i)
{
sand[j] = true;
}
}
}
}



2.

/*
* ACM Contest training
* Problem: 10235 - Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176
*
* @author Christoph Goettschkes
* @version 1.0, 10/25/2010
*
* Method : Sieve of Eratosthenes
* Status : Accepted
* Runtime: 0.748
*/

import java.util.*;
import java.io.*;

class Main {

private static Set<Integer> primes = null;

public static void main(String[] args) throws Exception {
sieve(1000000);

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(reader.readLine());

while (true) {
test(n);
if (!reader.ready())
break;
n = Integer.parseInt(reader.readLine());
}
}

public static void test(int n) {
if (n > 1 && n < 1000000) {
if (primes.contains(n)) {
if (primes.contains(reverse(n)) && reverse(n) != n) {
System.out.println(n + " is emirp.");
} else {
System.out.println(n + " is prime.");
}
} else {
System.out.println(n + " is not prime.");
}
}
}

private static int reverse(int n) {
int pot = (int) Math.floor(Math.log10(n));
int newN = 0;

while (n != 0) {
newN += (n % 10) * Math.pow(10, pot);
pot--;
n /= 10;
}
return newN;
}

public static void sieve(int upperBound) {
primes = new HashSet<Integer>();
int last = 0;

int upperBoundSquareRoot = (int) Math.sqrt(upperBound);
boolean[] isComposite = new boolean[upperBound + 1];
for (int m = 2; m <= upperBoundSquareRoot; m++) {
if (!isComposite[m]) {
primes.add(m);
last = m;
for (int k = m * m; k <= upperBound; k += m) {
isComposite[k] = true;
}
}
}

if (upperBoundSquareRoot == last)
upperBoundSquareRoot++;

for (int m = upperBoundSquareRoot; m <= upperBound; m++) {
if (!isComposite[m]) {
primes.add(m);
}
}
}
}



2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10235 Simply Emirp
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176
*
* @author Barny Porcio
* @version 1.0, 03/25/2010
*
* Method : Sieb des Eratosthenes
* Status : Accepted
* Runtime: 1.004
*/
import java.io.IOException;
import java.util.Scanner;


public class emirP {
static short[] answer;

/** Sieb des Eratosthenes, belegt emirp zahlen mit 1 und nicht prim zahlen mit -1 */
static void initialiser(){
answer = new short[1000001];
//belegt erstmal nur nichtprimzahlen mit -1
for (int i = 2;i<= Math.sqrt(answer.length);++i){
if (answer[i]!=-1){
for (int c=2;(c*i)<answer.length;++c){
answer[c*i]=-1;
}
}
}

//primzahlen, deren gespiegelte zahlen != sich selbst auch primzahlen sind werden auf 1 gesetzt
for (int i = 2;i<answer.length;++i){
if (answer[i]==0){

int reverse = 0;
int alt = i;
while (alt!= 0){
reverse = reverse * 10 + alt % 10;
alt = alt / 10;
}
if(reverse != i){
if (answer[reverse]==0){
answer[i]=1;
answer[reverse]=1;
}
}
}
}
}
/**
* @param args
*/
public static void main(String[] args)throws IOException {
initialiser();
Scanner scanner = new Scanner(System.in);
//es wird nur noch ueberpr√ľft ob der gesuchte wert 1, 0 oder -1 ist und die richtige ausgabe getroffen
while(scanner.hasNextInt()){
int temp = scanner.nextInt();
if (answer[temp]== 0)System.out.println(temp+" is prime.");
if (answer[temp]== -1)System.out.println(temp+" is not prime.");
if (answer[temp]== 1)System.out.println(temp+" is emirp.");
}

}

}


3. Martin Lambeck

package acm_10235_simply_emirp;

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
static boolean[] sieb = new boolean[1000000];

public static void main(String[] args)
{
Scanner sc = new Scanner(new BufferedInputStream(System.in));

fill(sieb.length);

while (sc.hasNextInt())
{
int n = sc.nextInt();

if (sieb[n])
{
if (sieb[reverse(n)] && (n != reverse(n)))
{
System.out.println(n + " is emirp.");

} else
{
System.out.println(n + " is prime.");
}

} else
{
System.out.println(n + " is not prime.");

}
// reverse(sc.nextInt());
// System.out.println(sieb[sc.nextInt()]);

}

}

public static void fill(int n)
{
int i = 1;
int mul;

Arrays.fill(sieb, true);
sieb[0] = false;
sieb[1] = false;

while (true)
{

i++;

mul = i * i;

if (!sieb[i])
continue;

if (mul >= n)
return;

while (mul < n)
{
sieb[mul] = false;
mul += i;
}

}
}

static int reverse(int n)
{
int rev = 0;
int div = 1;
int mod = 0;
int mul = 10000000;

while (div < 10000000)
{
mod = n % (div * 10);
n -= mod;
mod = mod / div;

div = div * 10;

rev += mul * mod;
mul = mul / 10;
}

while (rev % 10 == 0)
{
rev = rev / 10;
}

return rev;
}
}


4.


/**

 * Angewandte Mathematik, SS09, IFB 2C

 * ACM Problem 10235 - Simply Emirp

 * Link:
http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1176

 * @author Miesel Christoph

 * @author Seilbeck Robert

 * @author Wolfram Andre

 * @version 1.0 25.03.2009

 *

 * Status : Accepted

 * Runtime: 0.630

 */



import java.io.*;





public class Emirp {

    

    static boolean primzahltest(int aNumber)

    {

    boolean isPrim = true;

    if(aNumber==2) isPrim = true;

    else

    {

        double limit = Math.sqrt(aNumber);

        if(aNumber%2==0) isPrim = false;

        for(int i = 3; i<=limit; i+=2)

            {

          
 if(aNumber%i==0) isPrim = false;

            }

    }

    return isPrim;

    }

    

    

    public static void main(String[] args) throws
Exception

    {

        

        BufferedReader reader = new
BufferedReader(new InputStreamReader(System.in));

        String line = reader.readLine();

        int input = -1;

        int revert = 0;

        while(line!=null)

        {

            

            input =
Integer.parseInt(line);

            int tmp =
input;

            while(tmp != 0)

            {

              
 revert = revert * 10 + tmp % 10;

              
 tmp /= 10;

              
 

            }

        if(primzahltest(input) &&
primzahltest(revert) && input != revert)

          
 System.out.println(input+" is emirp.");

        else {

          
 if(!primzahltest(input)) System.out.println(input+" is not
prime.");

            else
System.out.println(input+" is prime.");

            }

        line = reader.readLine();

        revert = 0;

        }

        }

    }