Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -1,78 +1,108 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.Map;
|
||||
|
||||
public final class AchlllesNumbers {
|
||||
public class AchillesNumbers {
|
||||
|
||||
public static void main(String[] aArgs) {
|
||||
Set<Integer> perfectPowers = perfectPowers(500_000);
|
||||
List<Integer> achilles = achilles(1, 250_000, perfectPowers);
|
||||
List<Integer> totients = totients(250_000);
|
||||
private Map<Integer, Boolean> pps = new HashMap<>();
|
||||
|
||||
System.out.println("First 50 Achilles numbers:");
|
||||
for ( int i = 0; i < 50; i++ ) {
|
||||
System.out.print(String.format("%4d%s", achilles.get(i), ( ( i + 1 ) % 10 == 0 ) ? "\n" : " "));
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
System.out.println("First 50 strong Achilles numbers:");
|
||||
for ( int i = 0, count = 0; count < 50; i++ ) {
|
||||
if ( achilles.contains(totients.get(achilles.get(i))) ) {
|
||||
System.out.print(String.format("%6d%s", achilles.get(i), ( ++count % 10 == 0 ) ? "\n" : " "));
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
System.out.println("Number of Achilles numbers with:");
|
||||
for ( int i = 100; i < 1_000_000; i *= 10 ) {
|
||||
final int digits = String.valueOf(i).length() - 1;
|
||||
System.out.println(" " + digits + " digits: " + achilles(i / 10, i - 1, perfectPowers).size());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Integer> achilles(int aFrom, int aTo, Set<Integer> aPerfectPowers) {
|
||||
Set<Integer> result = new TreeSet<Integer>();
|
||||
final int cubeRoot = (int) Math.cbrt(aTo / 4);
|
||||
final int squareRoot = (int) Math.sqrt(aTo / 8);
|
||||
for ( int b = 2; b <= cubeRoot; b++ ) {
|
||||
final int bCubed = b * b * b;
|
||||
for ( int a = 2; a <= squareRoot; a++ ) {
|
||||
int achilles = bCubed * a * a;
|
||||
if ( achilles >= aTo ) {
|
||||
break;
|
||||
}
|
||||
if ( achilles >= aFrom && ! aPerfectPowers.contains(achilles) ) {
|
||||
result.add(achilles);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<Integer>(result);
|
||||
}
|
||||
|
||||
private static Set<Integer> perfectPowers(int aN) {
|
||||
Set<Integer> result = new TreeSet<Integer>();
|
||||
for ( int i = 2, root = (int) Math.sqrt(aN); i <= root; i++ ) {
|
||||
for ( int perfect = i * i; perfect < aN; perfect *= i ) {
|
||||
result.add(perfect);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Integer> totients(int aN) {
|
||||
List<Integer> result = IntStream.rangeClosed(0, aN).boxed().collect(Collectors.toList());;
|
||||
for ( int i = 2; i <= aN; i++ ) {
|
||||
if ( result.get(i) == i ) {
|
||||
result.set(i, i - 1);
|
||||
for ( int j = i * 2; j <= aN; j = j + i ) {
|
||||
result.set(j, ( result.get(j) / i ) * ( i - 1 ));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int totient(int n) {
|
||||
int tot = n;
|
||||
int i = 2;
|
||||
while (i * i <= n) {
|
||||
if (n % i == 0) {
|
||||
while (n % i == 0) {
|
||||
n /= i;
|
||||
}
|
||||
tot -= tot / i;
|
||||
}
|
||||
if (i == 2) {
|
||||
i = 1;
|
||||
}
|
||||
i += 2;
|
||||
}
|
||||
if (n > 1) {
|
||||
tot -= tot / n;
|
||||
}
|
||||
return tot;
|
||||
}
|
||||
|
||||
public void getPerfectPowers(int maxExp) {
|
||||
double upper = Math.pow(10, maxExp);
|
||||
for (int i = 2; i <= Math.sqrt(upper); i++) {
|
||||
double fi = i;
|
||||
double p = fi;
|
||||
while (true) {
|
||||
p *= fi;
|
||||
if (p >= upper) {
|
||||
break;
|
||||
}
|
||||
pps.put((int) p, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Boolean> getAchilles(int minExp, int maxExp) {
|
||||
double lower = Math.pow(10, minExp);
|
||||
double upper = Math.pow(10, maxExp);
|
||||
Map<Integer, Boolean> achilles = new HashMap<>();
|
||||
for (int b = 1; b <= (int) Math.cbrt(upper); b++) {
|
||||
int b3 = b * b * b;
|
||||
for (int a = 1; a <= (int) Math.sqrt(upper); a++) {
|
||||
int p = b3 * a * a;
|
||||
if (p >= (int) upper) {
|
||||
break;
|
||||
}
|
||||
if (p >= (int) lower) {
|
||||
if (!pps.containsKey(p)) {
|
||||
achilles.put(p, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return achilles;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
AchillesNumbers an = new AchillesNumbers();
|
||||
|
||||
int maxDigits = 8;
|
||||
an.getPerfectPowers(maxDigits);
|
||||
Map<Integer, Boolean> achillesSet = an.getAchilles(1, 5);
|
||||
List<Integer> achilles = new ArrayList<>(achillesSet.keySet());
|
||||
Collections.sort(achilles);
|
||||
|
||||
System.out.println("First 50 Achilles numbers:");
|
||||
for (int i = 0; i < 50; i++) {
|
||||
System.out.printf("%4d ", achilles.get(i));
|
||||
if ((i + 1) % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\nFirst 30 strong Achilles numbers:");
|
||||
List<Integer> strongAchilles = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (int n = 0; count < 30; n++) {
|
||||
int tot = an.totient(achilles.get(n));
|
||||
if (achillesSet.containsKey(tot)) {
|
||||
strongAchilles.add(achilles.get(n));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 30; i++) {
|
||||
System.out.printf("%5d ", strongAchilles.get(i));
|
||||
if ((i + 1) % 10 == 0) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\nNumber of Achilles numbers with:");
|
||||
for (int d = 2; d <= maxDigits; d++) {
|
||||
int ac = an.getAchilles(d - 1, d).size();
|
||||
System.out.printf("%2d digits: %d\n", d, ac);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue