Perfect totient numbers: Difference between revisions

Content added Content deleted
(Added implementation in Rust)
(Added implementation in D)
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|D}}==
<lang d>import std.stdio;
import std.numeric;

int[10000] cache;

bool is_perfect_totient(int num) {
int tot = 0;
for (int i = 1; i < num; i++) {
if (gcd(num, i) == 1) {
tot++;
}
}
int sum = tot + cache[tot];
cache[num] = sum;
return num == sum;
}

void main() {
int j = 1;
int count = 0;
while (count < 20) {
if (is_perfect_totient(j)) {
printf("%d ", j);
count++;
}
j++;
}
writeln(" ");
}
</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|Dart}}==
=={{header|Dart}}==
Line 883: Line 920:
}
}
</lang>
</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|Delphi}}==
=={{header|Delphi}}==