Hi Im trying to answer this question here:
Find the 4th prime number Z such that Z=NumberOfDigits(R) where Z is prime AND R is prime AND
where R=2p-1 where P is prime.
Example the 1st prime number Z is 2, because 2=NumberOfDigits(31) because 2 is prime and because
31=25-1 and because 5 is prime.
We are looking for the 2nd,3rd, 4th prime number Z in the Mageua Senoko series as well as its
corresponding R and P values.
Hints:
1 The 4th Z corresponds to a very large M. Take this into account when doing the calculation.
2 Please programme the solution to this problem in JAVA – We require your code
3 Computational efficiency is important.
4 Object orientation and inheritance MUST be used. i.e. Z is a prime, and a subset (subclass) of R,
R is also prime and a subset of P which is also prime.
My solution:
public class PrimeZ {
int firstPrimeNumOfZ=2;
int SecondPrimeNumOfZ;
int thirdPrimeNumOfZ;
int fourthPrimeNumOfZ;
long valueP;
long valueR;
public int getFourthPrimeNumOfZ() {
return fourthPrimeNumOfZ;
}
public void setFourthPrimeNumOfZ(int fourthPrimeNumOfZ) {
this.fourthPrimeNumOfZ = fourthPrimeNumOfZ;
}
public int getSecondPrimeNumOfZ() {
int firstPrimeNumOfZ=2;
int R=31;
int P=5;
R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
return SecondPrimeNumOfZ;
}
public void setSecondPrimeNumOfZ(int secondPrimeNumOfZ) {
SecondPrimeNumOfZ = secondPrimeNumOfZ;
}
public int getThirdPrimeNumOfZ() {
int P=0;
int R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
return thirdPrimeNumOfZ;
}
public void setThirdPrimeNumOfZ(int thirdPrimeNumOfZ) {
this.thirdPrimeNumOfZ = thirdPrimeNumOfZ;
}
public long getValueP() {
return valueP;
}
public void setValueP(long valueP) {
this.valueP = valueP;
}
public long getValueR() {
int P = 0;
int R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
return valueR;
}
public void setValueR(long valueR) {
this.valueR = valueR;
}
class PrimeR extends PrimeZ {
public int getPrimeR(){
int R;
int firstPrimeNumOfZ = 2;
int P=5;
{
R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
}
return R;
}
}
class PrimeP extends PrimeZ {
public int getPrimeP() {
int R=10;
int firstPrimeNumOfZ = 2;
int P = 0;
{
R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
}
return P;
}
}
public int formulsForTheAppl(int value,int powerOf){
int firstPrimeNumOfZ = 2;
int R = 31;
int P=5;
R =(int) (Math.pow(firstPrimeNumOfZ, P)-1);
if (Math.pow(value, powerOf)== 0){ /* pow(x, 0) returns 1 */
return 1;
}
else{
return (int) (Math.pow(value, powerOf - 1) * value);
}
}
public static void main(String[] args){
PrimeZ objPrime = new PrimeZ();
//PrimeR objPrimer = new PrimeR();
System.out.println("The SecondPrimeNumOfZ is:" +objPrime.fourthPrimeNumOfZ);
System.out.println("The thirdPrimeNumOfZ is:" +objPrime.fourthPrimeNumOfZ);
System.out.println("The fourthPrimeNumOfZ is:" +objPrime.fourthPrimeNumOfZ);
//System.out.println("The new value of PrimeR is:" + objPrimer.getPrimeR);
// System.out.println("The new value of PrimeP is:"+((PrimeP) objPrime).getPrimeP());
}
}
am I doing the right thing?
Software/Hardware used:
ASKED:
September 30, 2008 6:39 AM
UPDATED:
September 30, 2008 3:36 PM