Posts Tagged 'summation'

Partition Function

The problem is to enumerate all the ways in which a given number can be written as sum of two or more positive integers. For example 5 can be written as [4, 1], [3, 1, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1], [2, 2, 1] and [3, 2].

I used a recursion to solve the problem. The recursion works like this. Write 5 as 4 + 1. Recurse for 4. 5 can also be ...

Continue Reading ?
0

Project Euler : Finding Minimal Sum Path In A Matrix

The problem 81 of Project Euler gives a square matrix and requires one to find the minimal sum path. Specifically, it only required the sum of the numbers on the path. The question immediately reminded me of problem 67 and I set out solving with the same logic.

The logic has been explained in the following post of mine: Continue Reading ?

0

Project Euler : Numbers That Are Fifth Powers Of Their Digits

The idea in solving this problem was pretty simple. If you consider the digits a, b, c, d, e and f, the sum of their 5th powers will always be the same irrespective of their ordering. So, instead of iterating over all the numbers, I chose to iterate over all the collection of the digits. For each collection, find the sum of the fifth powers of the digits, get the digits of the sum ordered in ascending order ...

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

Project Euler : Evaluate Sum Of All Amicable Pairs

Once the task of finding sum of all divisors was taken care of, this problem held little challenge. I have mentioned how to compute the sum of all the divisors in an earlier post:

Sum Of Divisors

Take a number, find the sum of its divisors. If the sum is greater than the number itself, then find the sum of divisors of this sum. If the two sums are equal, ...

Continue Reading ?
0

Sum Of Divisors

Let n be an integer factorized as following:

The sum of divisors of n is:

where,

In the simpler case of , the sum is

This I learned from the article written by Hisanori Mishima found here. The idea translates into a nice little loop to find the sum of divisors. The Java implementation of it has been done ...

Continue Reading ?
1