Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
35
Task/Attractive-numbers/FutureBasic/attractive-numbers.basic
Normal file
35
Task/Attractive-numbers/FutureBasic/attractive-numbers.basic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
local fn IsPrime( n as NSUInteger ) as BOOL
|
||||
NSUInteger i
|
||||
|
||||
if ( n < 2 ) then exit fn = NO
|
||||
if ( n = 2 ) then exit fn = YES
|
||||
if ( n mod 2 == 0 ) then exit fn = NO
|
||||
for i = 3 to int(n^.5) step 2
|
||||
if ( n mod i == 0 ) then exit fn = NO
|
||||
next
|
||||
end fn = YES
|
||||
|
||||
local fn Factors( n as NSInteger ) as NSInteger
|
||||
NSInteger count = 0, f = 2
|
||||
|
||||
do
|
||||
if n mod f == 0 then count++ : n /= f else f++
|
||||
until ( f > n )
|
||||
end fn = count
|
||||
|
||||
void local fn AttractiveNumbers( limit as NSInteger )
|
||||
NSInteger c = 0, n
|
||||
|
||||
printf @"Attractive numbers through %d are:", limit
|
||||
for n = 4 to limit
|
||||
if fn IsPrime( fn Factors( n ) )
|
||||
printf @"%4d \b", n
|
||||
c++
|
||||
if ( c mod 10 == 0 ) then print
|
||||
end if
|
||||
next
|
||||
end fn
|
||||
|
||||
fn AttractiveNumbers( 120 )
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
attractivep(n):=block(ifactors(n),apply("+",map(second,%%)),if primep(%%) then true)$
|
||||
sublist(makelist(i,i,120),attractivep);
|
||||
69
Task/Attractive-numbers/Odin/attractive-numbers.odin
Normal file
69
Task/Attractive-numbers/Odin/attractive-numbers.odin
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import "core:fmt"
|
||||
main :: proc() {
|
||||
const_max :: 120
|
||||
fmt.println("\nAttractive numbers up to and including", const_max, "are: ")
|
||||
count := 0
|
||||
for i in 1 ..= const_max {
|
||||
n := countPrimeFactors(i)
|
||||
if isPrime(n) {
|
||||
fmt.print(i, " ")
|
||||
count += 1
|
||||
if count % 20 == 0 {
|
||||
fmt.println()
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.println()
|
||||
}
|
||||
/* definitions */
|
||||
isPrime :: proc(n: int) -> bool {
|
||||
switch {
|
||||
case n < 2:
|
||||
return false
|
||||
case n % 2 == 0:
|
||||
return n == 2
|
||||
case n % 3 == 0:
|
||||
return n == 3
|
||||
case:
|
||||
d := 5
|
||||
for d * d <= n {
|
||||
if n % d == 0 {
|
||||
return false
|
||||
}
|
||||
d += 2
|
||||
if n % d == 0 {
|
||||
return false
|
||||
}
|
||||
d += 4
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
countPrimeFactors :: proc(n: int) -> int {
|
||||
n := n
|
||||
switch {
|
||||
case n == 1:
|
||||
return 0
|
||||
case isPrime(n):
|
||||
return 1
|
||||
case:
|
||||
count, f := 0, 2
|
||||
for {
|
||||
if n % f == 0 {
|
||||
count += 1
|
||||
n /= f
|
||||
if n == 1 {
|
||||
return count
|
||||
}
|
||||
if isPrime(n) {
|
||||
f = n
|
||||
}
|
||||
} else if f >= 3 {
|
||||
f += 2
|
||||
} else {
|
||||
f = 3
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue