1. Member
Join Date
Jul 2012
Posts
2
Rep Power
0

## 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.

2. ## 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

3. Member
Join Date
Jul 2012
Posts
2
Rep Power
0

## Re: Java EKG program

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

4. ## 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•