-
-
Save Beritra/4e1a4440bf8203a7df1a8ba5f2f8f5ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestTest { | |
int num = 10000 * 10000; | |
public static void main(String[] args) { | |
long timestamp = System.currentTimeMillis(); | |
System.out.println(new TestTest().func()); | |
System.out.println(System.currentTimeMillis() - timestamp); | |
} | |
public int[] func2(int len) { | |
int[] anInt = new int[len + 1]; | |
for (int i = 0; i < anInt.length; i++) { | |
anInt[i]++; | |
} | |
for (int i = 2; i <= Math.sqrt(len); i++) { | |
for (int j = 2; j <= len / 2; j++) { | |
if (i * j > len) | |
break; | |
if (i > j) { | |
continue; | |
} | |
if (i != j) | |
anInt[i * j] += i + j; | |
else | |
anInt[i * j] += i; | |
} | |
} | |
System.out.println("complete"); | |
return anInt; | |
} | |
public int func() { | |
int count = 0; | |
int[] ints = func2(num); | |
for (int i = 2; i <= num; i++) { | |
if (ints[i] <= num && ints[i] != i && ints[ints[i]] == i) { | |
System.out.println(i + "," + ints[i]); | |
count++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment