1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10699 Count the factors
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&page=show_problem&problem=1640
*
* @author Patrick Bédat
* @version 1.0, 10/26/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.148
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main
{

public static void main(String... args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(reader.readLine());

int n = Integer.parseInt(st.nextToken());

while (n != 0)
{
System.out.printf("%d : %d%n",n,countDistinctPrimeFactors(n));
st = new StringTokenizer(reader.readLine());
n = Integer.parseInt(st.nextToken());
}
}

private static int countDistinctPrimeFactors(int n)
{
Set<Integer> primeFactors = new HashSet<Integer>();

for (int i = 2; n > 1; i++)
while (n % i == 0)
{
primeFactors.add(i);
n /= i;
}
return primeFactors.size();
}
}

2.


/

/**

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

* Problem: 10699 - Count the factors

* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=18&page=show_problem&problem=1640

* @author Viktoriya Ryabova

* @version 1.0, 05/02/2010

*

* Method : Ad-Hoc

* Status : accepted

* Runtime: 1.088

*/

import java.util.Scanner;

 

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner (System.in);

while(sc.hasNext()){

//einlesen einer Zahl von der Konsole

long number = sc.nextLong();

//beim null wird eingabe terminated

if(number<=1000000&&number!=0){

int j=0;

//berechnen primzzalen unter zahlfaktoren

for (int i=2; i<= number; i++){

if(number%i==0&&isPrime(i)){

j++;

}

}

System.out.println(number + " : "+j);

}

}

}

//überprüfen, ob zahl eine primzahl ist

public static boolean isPrime(long n) {

if (n < 2) {

return false;

}

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;

}

}

}