Posts Tagged 'series'

Project Euler : Expansion Of Continued Fraction For Square Root Of Two

Problem 57 of Project Euler is pretty simple forward. It is very easy to see the following relation:

Simple code and was done. Here’s that:

    public int getCount(int numberOfExpansions) {
        int count = 0;

        BigInteger numerator = BigInteger.valueOf(3);
   ...

Continue Reading ?
0

Project Euler : Count Of Lychrel Numbers Below 10000

Problem 55 of Project Euler explains what Lychrel numbers are and asks one to find the number of those below 10000. The only sticking point in the whole procedure is that after a few iterations the number become so large that BigInteger needs to be used. But otherwise, just follow the wording of the statement and the problem will be solved.

Here’s the outermost loop which does the counting:

    private static final ...
Continue Reading ?
0

Project Euler : Sum Of Both Diagonals In A 1001 By 1001 Spiral

This one I solved using just paper and pencil, and am happy about it. All that was required was a keen observation on how the numbers along the diagonal form out of the previous number. Lets take a look at one of the diagonals of the 5 x 5 spiral

21     22     23     24     25
20     07     08     09    ...
Continue Reading ?
0

Project Euler : Digits Of Sum of 1^1 + 2^2 + 3 ^ 3 …

Nothing to talk about here. Simple implementation.

Main class:

package problems_40_50;

public class Problem_48 {
	private static final long MAX_LENGTH = 10000000000L;

	/**
	 * Multiplies two long numbers and truncates the sum length to the MAX_LENGTH
	 *
	 * @return
	 */
	private long multiply(long a, long b) {
		return a * b % Problem_48.MAX_LENGTH;
	}

	public long sumOfSeries(int maxNumber) {
		long[] numberGrid = new long[maxNumber];
		for (int i = 0; i < maxNumber; i++)
			numberGrid[i] = i + 1;

		for (int i = 1; i < ...

Continue Reading ?
0