/**
 * Performance (time)
 * real	0m0.193s
 * user	0m0.158s
 * sys	0m0.044s
 */
public class IsPowerOfThree {
	
	public static boolean isPowerOfThree(int x) {
		if (x < 0) throw new IllegalArgumentException();
		// 0 and 1 fall through to true
		while (x > 1) {
			if (x % 3 == 0) {
				x = x/3;
			} else {
				return false;
			}
		}
		return true;
	}

	public static void main(String... args) {
		for (int i = 0; i < 1000000; i++) {
			if (isPowerOfThree(i)) {
				System.out.println(i + " is a power of three");
			} 
		}	

	}

}
@@ -207,42 +207,8 @@
 ();%0A
-%09%09// 0 and 1 fall through to true%0A
 %09%09wh
@@ -294,16 +294,57 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09// 0, 1 and cubes fall through to true%0A
 %09%09return

update a comment to be more accurate