1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #11466 (Largest Prime Devisor)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2461
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 03/27/2009
*
* Status : Accepted
* Runtime: 0.470
*/

import java.util.Scanner;

class Main {

/**
* LPD - Largest Prime Factor
*
* @param n: Long value giving the number to deal with
* @return Long representing the Largest Prime Factor
*/
public static Long lpd(Long n) {

Long p = Long.parseLong("0");
Long a = p;
double sqrt = Math.sqrt(n);

if(n==Long.parseLong("1"))
return Long.parseLong("-1");

//check if "2" is a factor.
if(n%2==0)
{
a = Long.parseLong("2");
p++;
while(n%2==0)
n = n/Long.parseLong("2");
}

//finding all primes. Setting the largest
for(Long j=Long.parseLong("3"); j*j<=n;j+=2)
if(n%j==0)
{
p++;
while(n%j==0)
n = n/j;
a = j;
}

//no prime factors found
if (n>1 && p==0)
return Long.parseLong("-1");

if (n>1 || (p==1 && n>1))
return n;

//Sqrt of given number is a prime
if (a==sqrt)
return Long.parseLong("-1");

//largest prime factor is 2
if (a<3)
return Long.parseLong("-1");

return a;
}


public static void main(String[] args) {

//setting up all needed variables
Scanner sc = new Scanner(System.in);
Long zero, number, lpd;
int next;
next = 1;

while(sc.hasNext() && next<=450)
{
zero = Long.parseLong("0");

//Read-in of a number
number = Math.abs(sc.nextLong());

if(number==zero)
break;

//calculate lpd
lpd = lpd(number);

//SystemOut
System.out.println(lpd);

next++;

}
}

}




2.


/**
* Angewandte Mathematik SS 09
11466 Largest Prime Divisor
* UVa Status: Accepted
* Run Time: 0.100
* Programming Language: C
* Date: 24.03.2009
* @author Doina Logofatu logofatu@hm.edu
*/

/*
- kritische Fälle: 1, -1, 32, 81, 49, -49, ...
*/

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

long long lpd(long long n){

long long j, a = 2;
int p = 0;

if(n<=2) return -1;

if(n%2==0) {p++; while(n%2==0) n/=2;}

if(n==1) return -1;

for(j=3; n!=1 && j*j<=n; j+=2){
if(n%j==0){
p++;
while(n%j==0) n/=j;
a = j;
}
}

if(p==0) return -1;
if(p==1&&n==1) return -1;
if(n>1) return n;

return a;

}

int main() {

long long n;

while(scanf("%lld", &n)==1 && n!=0) {

if(n<0)n*=-1;
printf ("%lld\n", lpd(n));

}

return 0;
}

3.

/**
* Angewandte Mathematik SS 09
11466 Largest Prime Divisor
* UVa Status: Accepted
* Run Time: 0.390
* Programming Language: Java
* Date: 26.03.2009
* @author Doina Logofatu logofatu@hm.edu
*/

/*
- kritische Fälle: 1, -1, 32, 81, 49, -49, ...
*/

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


public class Main {

static long lpd(long n) {
if(n<=2) {
return -1;
}

int p = 0;
if(n%2==0) {
p++;
while(n%2==0) {
n/=2;
}
}
if(n==1) {
return -1;
}

long a = 2;
for(long j=3; n!=1 && j*j<=n; j+=2) {
if(n%j==0){
p++;
while(n%j==0) n/=j;{
a = j;
}
}
}

if(p==0 || (p==1&&n==1) ) {
return -1;
}
else if(n>1) {
return n;
}
else {
return a;
}
}

public static void main(String[] args) {

BufferedInputStream bin = new BufferedInputStream(System.in);
PrintWriter w = new PrintWriter(System.out);
Scanner s = new Scanner(bin);
long n;

while(s.hasNextLong() && (n=s.nextLong())!=0 ) {
if(n<0)n*=-1;
w.println(lpd(n));
}

w.flush(); //flush the writer
}

}