Perfect totient numbers: Difference between revisions
Content added Content deleted
(Added implementation in Tcl) |
(Added implementation in Dart) |
||
Line 851: | Line 851: | ||
{{out}} |
{{out}} |
||
<pre>3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571</pre> |
<pre>3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571</pre> |
||
=={{header|Dart}}== |
|||
<lang dart>import "dart:io"; |
|||
var cache = List<int>.filled(10000, 0, growable: true); |
|||
void main() { |
|||
cache[0] = 0; |
|||
var count = 0; |
|||
var i = 1; |
|||
while (count < 20) { |
|||
if (is_perfect_totient(i)) { |
|||
stdout.write("$i "); |
|||
count++; |
|||
} |
|||
i++; |
|||
} |
|||
print(" "); |
|||
} |
|||
bool is_perfect_totient(n) { |
|||
var tot = 0; |
|||
for (int i = 1; i < n; i++ ) { |
|||
if (i.gcd(n) == 1) { |
|||
tot++; |
|||
} |
|||
} |
|||
int sum = tot + cache[tot]; |
|||
cache[n] = sum; |
|||
return n == sum; |
|||
} |
|||
</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
Line 910: | Line 943: | ||
readln; |
readln; |
||
end.</lang> |
end.</lang> |
||
{{out}} |
|||
<pre> |
|||
3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571 |
|||
</pre> |
|||
=={{header|Draco}}== |
=={{header|Draco}}== |