Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,51 +1,52 @@
|
|||
/*Abhishek Ghosh, 7th December 2018*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
int totient(int n){
|
||||
int tot = n,i;
|
||||
int
|
||||
totient(int n)
|
||||
{
|
||||
int result = n;
|
||||
|
||||
for(i=2;i*i<=n;i+=2){
|
||||
if(n%i==0){
|
||||
while(n%i==0)
|
||||
n/=i;
|
||||
tot-=tot/i;
|
||||
for (int i=2; i*i <= n; i+=2) {
|
||||
if (n % i == 0) {
|
||||
while (n % i == 0)
|
||||
n /= i;
|
||||
result -= result / i;
|
||||
}
|
||||
|
||||
if(i==2)
|
||||
i=1;
|
||||
if (i == 2)
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if(n>1)
|
||||
tot-=tot/n;
|
||||
|
||||
return tot;
|
||||
if (n > 1)
|
||||
result -= result / n;
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int count = 0,n,tot;
|
||||
int count, n, tot;
|
||||
|
||||
printf(" n %c prime",237);
|
||||
printf("\n---------------\n");
|
||||
|
||||
for(n=1;n<=25;n++){
|
||||
printf(" n phi prime\n");
|
||||
printf("--------------\n");
|
||||
|
||||
count = 0;
|
||||
for (n = 1; n <= 25; n++) {
|
||||
tot = totient(n);
|
||||
|
||||
if(n-1 == tot)
|
||||
if (tot == n - 1)
|
||||
count++;
|
||||
|
||||
printf("%2d %2d %s\n", n, tot, n-1 == tot?"True":"False");
|
||||
printf("%2d %2d %s\n", n, tot, tot == (n-1) ? "true" : "false");
|
||||
}
|
||||
|
||||
printf("\nNumber of primes up to %6d =%4d\n", 25,count);
|
||||
|
||||
for(n = 26; n <= 100000; n++){
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (n = 26; n <= 100000; n++) {
|
||||
tot = totient(n);
|
||||
if(tot == n-1)
|
||||
if (tot == n-1)
|
||||
count++;
|
||||
|
||||
if(n == 100 || n == 1000 || n%10000 == 0){
|
||||
if (n == 100 || n == 1000 || n == 10000) {
|
||||
printf("\nNumber of primes up to %6d = %4d\n", n, count);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,15 @@
|
|||
func totient n .
|
||||
fastfunc totient n .
|
||||
tot = n
|
||||
i = 2
|
||||
while i <= sqrt n
|
||||
if n mod i = 0
|
||||
while n mod i = 0
|
||||
n = n div i
|
||||
.
|
||||
while n mod i = 0 : n = n div i
|
||||
tot -= tot div i
|
||||
.
|
||||
if i = 2
|
||||
i = 1
|
||||
.
|
||||
if i = 2 : i = 1
|
||||
i += 2
|
||||
.
|
||||
if n > 1
|
||||
tot -= tot div n
|
||||
.
|
||||
if n > 1 : tot -= tot div n
|
||||
return tot
|
||||
.
|
||||
numfmt 0 3
|
||||
|
|
@ -23,17 +17,13 @@ print " N Prim Phi"
|
|||
for n = 1 to 25
|
||||
tot = totient n
|
||||
x$ = " "
|
||||
if n - 1 = tot
|
||||
x$ = " x "
|
||||
.
|
||||
if n - 1 = tot : x$ = " x "
|
||||
print n & x$ & tot
|
||||
.
|
||||
print ""
|
||||
for n = 1 to 100000
|
||||
tot = totient n
|
||||
if n - 1 = tot
|
||||
cnt += 1
|
||||
.
|
||||
if n - 1 = tot : cnt += 1
|
||||
if n = 100 or n = 1000 or n = 10000 or n = 100000
|
||||
print n & " - " & cnt & " primes"
|
||||
.
|
||||
|
|
|
|||
17
Task/Totient-function/PascalABC.NET/totient-function.pas
Normal file
17
Task/Totient-function/PascalABC.NET/totient-function.pas
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
uses school;
|
||||
|
||||
function totient(n: int64) := (1..n).Select(k -> (if gcd(n, k) = 1 then 1 else 0)).Sum;
|
||||
|
||||
function is_prime(n: int64) := totient(n) = n - 1;
|
||||
|
||||
begin
|
||||
foreach var n in 1..25 do
|
||||
writeln('φ(', n, ') = ', totient(n), if is_prime(n) then ', is prime' else '');
|
||||
var count := 0;
|
||||
foreach var n in 1..100_000 do
|
||||
begin
|
||||
count += if is_prime(n) then 1 else 0;
|
||||
if n in |100, 1000, 10_000, 100_000| then
|
||||
writeln('Primes up to ', n, ': ', count);
|
||||
end;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue