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
package euler; | |
public class PrimesBelow { | |
public static void main(String[] args) { | |
int n = 2_000_000; | |
// initially assume all integers are prime | |
boolean[] isPrime = new boolean[n+1]; | |
for (int i = 2; i <= n; i++) { |
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
package euler; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.math.BigInteger; | |
public class LongSum { | |
public static void main(String[] args) throws Throwable { | |
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
package euler; | |
import java.math.BigInteger; | |
public class BigPow { | |
public static void main(String[] args) { | |
BigInteger n = BigInteger.valueOf(2).pow(1000); | |
System.out.println(sum(n.toString())); | |
} | |
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
package euler; | |
public class NumWords { | |
public static void main(String[] args) { | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 1; i <= 1000; i++) { | |
sb.append(numToWord(i)); | |
} | |
System.out.println(sb.toString().length()); |
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
package euler; | |
import java.math.BigInteger; | |
public class BigFact { | |
public static void main(String[] args) { | |
System.out.println(sum(f(BigInteger.valueOf(100)).toString())); | |
} | |
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
package euler; | |
import java.math.BigInteger; | |
import java.util.HashMap; | |
public class Fib { | |
private static HashMap<BigInteger, BigInteger> map = new HashMap<>(); | |
public static void main(String[] args) { | |
for (int i = 1; i < Integer.MAX_VALUE; i++) { | |
if (f(BigInteger.valueOf(i)).toString().length() == 1000) { |
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
package euler; | |
public class BasePalindrome { | |
public static void main(String[] args) { | |
int sum = 0; | |
for (int i = 0; i < 1_000_000; i++) { | |
if (isPalindrome(Integer.valueOf(i).toString()) && isPalindrome(Integer.toBinaryString(i))) { | |
sum += i; | |
} |
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
package euler; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.util.Arrays; | |
public class Names { | |
public static void main(String[] args) throws Throwable { | |
BufferedReader br = new BufferedReader(new FileReader(new File("p022_names.txt"))); |
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
package euler; | |
import java.math.BigInteger; | |
public class SelfPowers { | |
public static void main(String[] args) { | |
BigInteger sum = BigInteger.ZERO; | |
for (int i = 1; i <= 1000; i++) { | |
sum = sum.add(BigInteger.valueOf(i).pow(i)); | |
} |
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
package euler; | |
public class Pandigital { | |
public static void main(String[] args) { | |
int n = 1_000_000_000; | |
// initially assume all integers are prime | |
boolean[] isPrime = new boolean[n+1]; | |
for (int i = 2; i <= n; i++) { | |
isPrime[i] = true; |