/** * Returns whether the number is semiprime. */ public static boolean isPQ(lon
ID: 3694457 • Letter: #
Question
/**
* Returns whether the number is semiprime.
*/
public static boolean isPQ(long number) {
/*
to do
*/
}
/**
* Returns new vector with elements generated from the
* pq number sequence starting from the specified value.
*/
public static Vector pq(int length, long start) {
/*
to do
length 4, start 1 => [4 6 9 10]
length 4, start 4 => [4 6 9 10]
length 4, start -1 => [4 6 9 10]
length 4, start 42 => [46 49 51 55]
*/
}
Explanation / Answer
Ans;
/**
* Returns whether the number is semiprime.
*/
public static boolean isPQ(long number) {
/*
to do
*/
for(int i = 2; i <= Math.sqrt(number); i++) {
if(number % i == 0)
{
boolean flag = true;
for(int j = 2; j <= Math.sqrt(i); j++)
if(i % j == 0)
flag = false;
if(flag == false)
return false;
}
return true;
}
/**
* Returns new vector with elements generated from the
* pq number sequence starting from the specified value.
*/
public static Vector pq(int length, long start) {
/*
to do
length 4, start 1 => [4 6 9 10]
length 4, start 4 => [4 6 9 10]
length 4, start -1 => [4 6 9 10]
length 4, start 42 => [46 49 51 55]
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.