UVA – 10006 – Carmichael Numbers

Actually this all what it gets to solve this problem. πŸ˜€ πŸ˜€
The Carmichael Numbers within the range given are only 16 numbers, you can pre compute them or actually copy them from The On-Line Encyclopedia of Integer Sequences
but this is cheating don’t do that πŸ˜€ here it is the Provoking solution πŸ˜›
the original solution is discussed further below.

import java.util.Arrays;
import java.util.Scanner;
import System.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] ar = { 561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973, 75361 };
		int n=-1;
		while((n =in.nextInt())!=0)
			.out.println((Arrays.binarySearch(ar, n) >=0? "The number "+ n + " is a Carmichael number." : n + " is normal."));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: