1.

import java.util.HashMap;
import java.util.Scanner;

/**
* Angewandte Mathematik, SS11
* Problem: 11466 - Largest Prime Divisor
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2461
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 10/04/2011
*
* Method : Primfaktorzerlegung und immer den gr¨§ten sich merken. Ist die Zahl negativ und ist das
* Ergebnis nicht gleich der Ausgangszahl kann das Resultat zur¾ckgegeben werden. War die Ausgangszahl
* positiv muss noch ¾berpr¾ft werden, ob das Resultat nicht die einzige Primzahl ist.
* Falls die Ausgangszahl eine Primzahl ist oder eine Potenz einer Primzahl wird -1 zur¾ckgegeben.
* Beispiele: 4=2*2 => -1, -4=2*(-2) => 2, 17 = 17 => -1, 32 = 2^5 => -1, usw...
* Status : Accpeted
* Runtime: 0.636
*/

public class Main
{
private static HashMap<Long,Long> largestPrime = new HashMap<Long,Long>();

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

while((number = sc.nextLong()) != 0)
{
divider = getLargestPrimeDivisor(number);
System.out.println(divider);
}
}

/**
* Liefert eine HashMap mit key=Primfaktor und value=Anzahl der
* nat¾rlichen Zahl n zur¾ck. D.h. es
* wird die komplette Primfaktorzerlegung durchgef¾hrt
* @param n nat¾rliche Zahl
* @return Primfaktoren mit der Anzahl
*/
public static long getLargestPrimeDivisor(long n)
{
boolean neg = false;
if(n<0)
{
neg = true;
}
n = Math.abs(n);
if(largestPrime.containsKey(n))
{
return largestPrime.get(n);
}
else if(n==1 || n==-1)
{
return -1;
}

long result = -1;
long number = n;
while (n % 2 == 0)
{
n /= 2;
result = 2;
}
long counter = 3;
long tmp = n;

while (counter <= ((double)Math.sqrt(tmp)+1))
{
if (n % counter == 0)
{
n /= counter;
result = counter;
}
else
{
counter += 2;
}
}
//System.out.println(number);
//System.out.println(result);
if(result == -1 || result == number)
{
result = -1;
}
else if(n>result)
{
result = n;
}
else if(number%result == 0 && !neg)
{
while(number%result == 0)
{
number = number/result;
}
if(number==1)
{
result = -1;
}
}
largestPrime.put(number, result);
return result;
}

}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 11466 Largest Prime Divisor
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2461
*
* @author Weber Christian
* @author Waldleitner Christoph
* @author Wolff Marco
* @version 1.0, 04/12/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.804
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


public class LargestPrimeDivisor
{

public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int max = 10000000;
long[] prime;
prime=new long[max];
int len=0;
boolean flag[]=new boolean[max];
Arrays.fill(flag,true);
for(int i=2;i<max;i++)
{
if(!flag[i])
continue;
prime[len++]=i;
for(int j=i;(long)i*j<max;j++)
flag[i*j]=false;
}

String input = "";
while(!input.equals("0"))
{
input = br.readLine();

if(input.equals("0"))
{
continue;
}

long number = Long.parseLong(input);
if(number <0)
{
number *= -1;
}

if(number == 1)
{
System.out.println("-1");
continue;
}

Map<Long, Integer> primfaktors = new HashMap<Long, Integer>();
for(int i=0; i<len;i++)
{
long x = prime[i];
if(number%x == 0)
{
int Anzahl = 1;
number/=x;
while(number%x == 0)
{
Anzahl++;
number/=x;
}
primfaktors.put(x, Anzahl);
}
if(number == 1)
{
break;
}
}
if (number > 1)
{
primfaktors.put((long)number, 1);
}

if(primfaktors.size() == 1)
{
System.out.println("-1");
}
else
{
long lulz = 0;
for(Map.Entry<Long,Integer> x : primfaktors.entrySet())
{
if(x.getKey() > lulz)
{
lulz = x.getKey();
}
}
System.out.println(Long.toString(lulz));
}
}
}
}

.---------------------------------------------------------

1.
/*
* ACM Contest training
* Problem: 11466 - Largest Prime Divisor
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=26&problem=2461&mosmsg=Submission+received+with+ID+8383065
*
* @author Christoph Goettschkes
* @version 1.0, 11/08/2010
*
* Method : Sieve of Eratosthenes
* Status : Accepted
* Runtime: 1.388
*/

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

class Main
{
static List<Integer> primes = new LinkedList<Integer>();

public static void main(String[] args) throws IOException
{
// max input has not more than 14 digits. Math.sqrt(10**14-1) = 9999999.9...
sieve(9999999);

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

long cur = Long.parseLong(reader.readLine());

while (cur != 0) {
if (cur == 1 || cur == -1)
System.out.println(-1);
else
System.out.println(factor(Math.abs(cur)));
cur = Long.parseLong(reader.readLine());
}
}

public static long factor(long n)
{
Set<Long> set = new HashSet<Long>();

for(int p : primes) {
while (n % p == 0) {
set.add((long)p);
n /= p;
}
if (p > n)
break;
}

if (n > 1)
set.add(n);

return set.size() == 1 ? -1 : Collections.max(set);
}

public static void sieve(int upperBound) {
long last = 0;

long upperBoundSquareRoot = (int) Math.sqrt(upperBound);
BitSet isComposite = new BitSet(upperBound);

for (long m = 2; m <= upperBoundSquareRoot; m++) {
if (!isComposite.get((int)m)) {
primes.add((int)m);
last = m;
for (long k = m * m; k <= upperBound; k += m) {
isComposite.set((int)k, true);
}
}
}

if (upperBoundSquareRoot == last)
upperBoundSquareRoot++;

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