Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
52
Task/Totient-function/D/totient-function.d
Normal file
52
Task/Totient-function/D/totient-function.d
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import std.stdio;
|
||||
|
||||
int totient(int n) {
|
||||
int tot = n;
|
||||
|
||||
for (int i = 2; i * i <= n; i += 2) {
|
||||
if (n % i == 0) {
|
||||
while (n % i == 0) {
|
||||
n /= i;
|
||||
}
|
||||
tot -= tot / i;
|
||||
}
|
||||
if (i==2) {
|
||||
i = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 1) {
|
||||
tot -= tot / n;
|
||||
}
|
||||
return tot;
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(" n φ prime");
|
||||
writeln("---------------");
|
||||
|
||||
int count = 0;
|
||||
for (int n = 1; n <= 25; n++) {
|
||||
int tot = totient(n);
|
||||
|
||||
if (n - 1 == tot) {
|
||||
count++;
|
||||
}
|
||||
|
||||
writefln("%2d %2d %s", n,tot, n - 1 == tot);
|
||||
}
|
||||
writeln;
|
||||
|
||||
writefln("Number of primes up to %6d = %4d", 25, count);
|
||||
for (int n = 26; n <= 100_000; n++) {
|
||||
int tot = totient(n);
|
||||
|
||||
if (n - 1 == tot) {
|
||||
count++;
|
||||
}
|
||||
|
||||
if (n == 100 || n == 1_000 || n % 10_000 == 0) {
|
||||
writefln("Number of primes up to %6d = %4d", n, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue