How to generate a number that has seven divisors?

For homework, I need logic to find a series of numbers from 1 to 1000 that have exactly seven divisors.

(Ideally, the code can be easily modified to generate prime numbers.)

+3
source share
4 answers

You need a loop (for a loop) from for n = 1 to 1000and inside this loop, another loop for m = 1 to ninside this loop test, if n/m = integer (no remainder)and if it increments the div counter. At the end of the second cycle, check if the counter is div 7 if it writes the number on the screen.

EDIT: for prime numbers, the div counter should be 2!

+1
source

p. p^6. : 1, p, p^2, p^3,..., p^6.

+9

n = product(p_i ^ k_i)

d = product(k_i + 1)

divisors (. divisor ). , n , 6. , .

+7

, , .

, , , N = N1 ^ a * N2 ^ b; N1 N2 * b .

Thus, for 7 coefficients, the number should have the form N = a ^ 6, where a is a prime number.

e.g. 2 ^ 6 (64), 3 ^ 6 (729).

EDIT: Using this logic, it would be easier to generate quicly numbers. You can easily generate perfect squares and a perfect cube <1000. And check both lists for common numbers.

+2
source

All Articles