1.

/*

Robert Reichart
Elvin Uzeirovic
Martin Pesl
IFB2C

960 - Gaussian Primes
Runtime: 1.100

Submission: 2009-04-01 14:16:51

*/


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

public class Main {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// Einlesen des InputStreams und Abspeichern als ein langer String
BufferedReader input = new BufferedReader(new InputStreamReader(
System.in));
for (String line = input.readLine(); line != null; line = input
.readLine()) {
String[] zahl = line.split(" ");
if (zahl.length == 2) {
int zahl1 = Integer.parseInt(zahl[0]);
int zahl2 = Integer.parseInt(zahl[1]);
if (zahl1 != 0 && zahl2 != 0) {
if (prims((zahl1 * zahl1) + (zahl2 * zahl2))) {
System.out.println("P");
continue;
} else {
System.out.println("C");
continue;
}
}
if (zahl1 == 0 && prims(Math.abs(zahl2))) {
if (Math.abs(zahl2) % 4 == 3) {
System.out.println("P");
continue;
} else {
System.out.println("C");
continue;
}
}
if (zahl2 == 0 && prims(Math.abs(zahl1))) {
if (Math.abs(zahl1) % 4 == 3) {
System.out.println("P");
continue;
} else {
System.out.println("C");
continue;
}
}
}
}
}

static boolean prims(int werte) {
int sum = 0;
int index = 0;
boolean returner = false;
int n = werte; // Initialisierung von "n"
int k = 2;
int i = 1;

while (k < n && i != 0) {
i = n % k;
k = k + 1;
}
if (i != 0) {
returner = true;
}

return returner;
}
}



2.

/**
* Angewandte Mathematik SS 09
960 Gaussian Primes
* UVa Status: Accepted
* Run Time: 0.010
* Programming Language: C
* @author Doina Logofatu logofatu@hm.edu
*/

#include <stdio.h>
#include <math.h>

int prim( int n){
int i, sqrt_n;
if(n<2) return 0;
if(n==2) return 1;
if(n%2 == 0) return 0;
sqrt_n = (int)sqrt(n);
for(i=3; i<=sqrt_n; i+=2)
if(n%i==0) return 0;
return 1;

}

int main() {
int re, im;
int n, i;


scanf("%d", &n);

// for(i=0; i<n; i++){

while(scanf("%d %d", &re, &im)==2) {

if(re!=0 && im!=0) {
if(prim(re*re+im*im)) printf ("%c", 'P');
else printf ("%c", 'C');

}

if(re==0 && im!=0) {
if(prim(abs(im)) && abs(im)%4==3) printf ("%c", 'P');
else printf ("%c", 'C');

}

if(re!=0 && im==0) {
if(prim(abs(re)) && abs(re)%4==3) printf ("%c", 'P');
else printf ("%c", 'C');

}

if(i<n-1) printf ("\n");

}

return 0;
}