# Java EKG program

• 07-12-2012, 03:40 AM
Confushous
Java EKG program
I am having trouble starting a program to compute the ekg. can anyone help

• Every number after that is the smallest number that is not in the sequence, and shares a factor larger than 1 with the last number

The first 10 numbers in the EKG sequence are

1,2,4,6,3,9,12,8,10,5

The program you turn in is to read in an integer n and compute and print the first n terms in the EKG sequence.

Your program should also include a function (or method) to compute GCD using Euclid’s algorithm (which is found on page 4 of your book). You are to use this function to determine if a candidate shares a factor larger than 1 with the last number in the sequence.
• 07-12-2012, 10:21 AM
JosAH
Re: Java EKG program
Are the numbers 1 and 2 supposed to be the first two numbers in that sequence by definition?

kind regards,

Jos
• 07-12-2012, 02:34 PM
Confushous
Re: Java EKG program
Quote:

Originally Posted by Confushous
I am having trouble starting a program to compute the ekg. can anyone help

• Every number after that is the smallest number that is not in the sequence, and shares a factor larger than 1 with the last number

The first 10 numbers in the EKG sequence are

1,2,4,6,3,9,12,8,10,5

The program you turn in is to read in an integer n and compute and print the first n terms in the EKG sequence.

Your program should also include a function (or method) to compute GCD using Euclid’s algorithm (which is found on page 4 of your book). You are to use this function to determine if a candidate shares a factor larger than 1 with the last number in the sequence.

Yes 1 and 2 are always the first two numbers
• 07-12-2012, 04:28 PM
JosAH
Re: Java EKG program
What's the problem then? Try each number n: if it's not in the set already and the gcd(lastNumber, n) > 1, add n to the set and repeat.

kind regards,

Jos