Largest proper divisor of n: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: More efficient.) |
m (→{{header|Wren}}: Oops) |
||
Line 54: | Line 54: | ||
for (n in 2..100) { |
for (n in 2..100) { |
||
if (n % 2 == 0) { |
if (n % 2 == 0) { |
||
Fmt.write("$2d ", n / 2) |
Fmt.write("$2d ", n / 2) |
||
} else { |
} else { |
||
Fmt.write("$2d ", Int.properDivisors(n)[-1]) |
Fmt.write("$2d ", Int.properDivisors(n)[-1]) |
Revision as of 15:26, 1 June 2021
Largest proper divisor of n 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.
- Task
- a(1) = 1; for n > 1, a(n) = largest proper divisor of n, where n < 101 .
Ring
<lang ring> see "working..." + nl see "Largest proper divisor of n are:" + nl see "1 " row = 1 limit = 100
for n = 2 to limit
for m = 1 to n-1 if n%m = 0 div = m ok next row = row + 1 see "" + div + " " if row%10 = 0 see nl ok
next
see "done..." + nl </lang>
- Output:
working... Largest proper divisor of n are: 1 1 1 2 1 3 1 4 3 5 1 6 1 7 5 8 1 9 1 10 7 11 1 12 5 13 9 14 1 15 1 16 11 17 7 18 1 19 13 20 1 21 1 22 15 23 1 24 7 25 17 26 1 27 11 28 19 29 1 30 1 31 21 32 13 33 1 34 23 35 1 36 1 37 25 38 11 39 1 40 27 41 1 42 17 43 29 44 1 45 13 46 31 47 19 48 1 49 33 50 done...
Wren
<lang ecmascript>import "/math" for Int import "/fmt" for Fmt
System.print("The largest proper divisors for numbers in the interval [1, 100] are:") System.write(" 1 ") for (n in 2..100) {
if (n % 2 == 0) { Fmt.write("$2d ", n / 2) } else { Fmt.write("$2d ", Int.properDivisors(n)[-1]) } if (n % 10 == 0) System.print()
}</lang>
- Output:
The largest proper divisors for numbers in the interval [1, 100] are: 1 1 1 2 1 3 1 4 3 5 1 6 1 7 5 8 1 9 1 10 7 11 1 12 5 13 9 14 1 15 1 16 11 17 7 18 1 19 13 20 1 21 1 22 15 23 1 24 7 25 17 26 1 27 11 28 19 29 1 30 1 31 21 32 13 33 1 34 23 35 1 36 1 37 25 38 11 39 1 40 27 41 1 42 17 43 29 44 1 45 13 46 31 47 19 48 1 49 33 50