Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
(Clarified that 'factors' include unity and the number itself.) |
(Added Go) |
||
Line 6: | Line 6: | ||
Show the first 15 items of this sequence. |
Show the first 15 items of this sequence. |
||
=={{header|Go}}== |
|||
<lang go>package main |
|||
import "fmt" |
|||
func countDivisors(n int) int { |
|||
count := 0 |
|||
for i := 1; i*i <= n; i++ { |
|||
if n%i == 0 { |
|||
if i == n/i { |
|||
count++ |
|||
} else { |
|||
count += 2 |
|||
} |
|||
} |
|||
} |
|||
return count |
|||
} |
|||
func main() { |
|||
const max = 15 |
|||
fmt.Println("The first", max, "anti-primes plus are:") |
|||
for i, next := 1, 1; next <= max; i++ { |
|||
if next == countDivisors(i) { |
|||
fmt.Printf("%d ", i) |
|||
next++ |
|||
} |
|||
} |
|||
fmt.Println() |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 15 anti-primes plus are: |
|||
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
Revision as of 08:13, 9 April 2019
Sequence: smallest number greater than previous term with exactly n divisors is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
The Anti-primes Plus sequence are the natural numbers in which each nth item has n factors, including 1 and itself.
Task
Show the first 15 items of this sequence.
Go
<lang go>package main
import "fmt"
func countDivisors(n int) int {
count := 0 for i := 1; i*i <= n; i++ { if n%i == 0 { if i == n/i { count++ } else { count += 2 } } } return count
}
func main() {
const max = 15 fmt.Println("The first", max, "anti-primes plus are:") for i, next := 1, 1; next <= max; i++ { if next == countDivisors(i) { fmt.Printf("%d ", i) next++ } } fmt.Println()
}</lang>
- Output:
The first 15 anti-primes plus are: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
Ring
<lang ring>
- Project : ANti-primes
see "working..." + nl see "wait for done..." + nl + nl see "the first 15 Anti-primes Plus are:" + nl + nl num = 1 n = 0 result = list(15) while num < 16
n = n + 1 div = factors(n) if div = num result[num] = n num = num + 1 ok
end see "[" for n = 1 to len(result)
if n < len(result) see string(result[n]) + "," else see string(result[n]) + "]" + nl + nl ok
next see "done..." + nl
func factors(an)
ansum = 2 if an < 2 return(1) ok for nr = 2 to an/2 if an%nr = 0 ansum = ansum+1 ok next return ansum
</lang>
- Output:
working... wait for done... the first 15 Anti-primes Plus are: [1,2,4,6,16,18,64,66,100,112,1024,1035,4096,4288,4624] done...