Prime Number

From Hack Wars Wiki

Jump to: navigation, search

Outdated, should be deleted. - aoi

Challenge Information for Prime Number
Challenge Prime Number
Code 10
Input Example 3 (Int)
Output Example Prime (String)
Level 0
Profit $0
Experience 0 to each stat
Description Determine if the number is prime or not. If it is return "Prime", if not return "Not Prime".


Solution

int i = 2;
int num = getInputInt();
boolean notPrime = false;
 
while(i <= sqrt( (float) num) )
{
	if(num % i == 0)
	{
		notPrime = true;
		setOutputString("Not Prime");
	}
 
	if(notPrime == true)
	{
		i = num - 1;
	}
 
	i++;
}
 
if(notPrime == false)
{
	setOutputString("Prime");
}
Personal tools