for all

*Solution:* Note that we obviously have

and using the hypothesis we obtain that

for every . Now we have two options. Suppose the image of is unbounded. Then, since if we fix it would follow that has arbitrarily large divisor, which is not possible unless . This is one solution, as it can easily be checked.

The other alternative is that is bounded. If this is true, then there is a value of which is repeated for an infinite increasing sequence : . It follows that

for every and for defined as above. Since the fraction

is an integer and it converges to as it follows that for large enough we have . This implies that , and this is independent of . Therefore is constant. From the previous relation we have so the only possible constant is .

]]>

**Problem 2.** Consider an acute-angled triangle with and let be its circumscribed circle. Let and be the tangents to the circle at points and , respectively, and let be their intersection. The straight line passing through the point and parallel to intersects in point . The straight line passing through the point and parallel to intersects in point . The circumcircle of the triangle intersects in , where is located between and . The circumcircle of the triangle intersects the line (or its extension) in , where is located between and .

Prove that , , and are concurrent.

**Problem 3.** Let denote the set of positive integers. Find all functions such that

for all

**Problem 4.** On a circular table sit students. First, each student has just one candy. At each step, each student chooses one of the following actions:

- (A) Gives a candy to the student sitting on his left or to the student sitting on his right.
- (B) Separates all its candies in two, possibly empty, sets and gives one set to the student sitting on his left and the other to the student sitting on his right.

At each step, students perform the actions they have chosen at the same time. A distribution of candy is called legitimate if it can occur after a finite number of steps. Find the number of legitimate distributions.

(Two distributions are different if there is a student who has a different number of candy in each of these distributions.)

Source: AoPS

]]>

*Mathematical Mind-Benders, Peter Winkler*

**Hint: **Work with remainders modulo 9.

]]>

Recently, I decided to try and see if I can do some more of these problems. I cannot say that I’ve acquired some new techniques between 2012-2016 concerning the mathematics involved in these problems. My research topics are usually quite different and my day to day programming routines are more about constructing new stuff which works fast enough than optimizing actual code. Nevertheless, I have some experience coding in Matlab, and I realized that nested loops are to be avoided. Vectorizing the code can speed up things 100 fold.

So the point of Project Euler tasks is making things go well for large numbers. Normally all problems are tested and should run within a minute on a regular machine. This brings us to choosing the right algorithms, the right simplifications and finding the complexity of the algorithms involved.

For example if you need to compute a certain sum what is the best way to proceed? Computing each in turn and summing them up in a loop gives us an algorithm. This means that computation time is roughly proportional to (this depends also on , but let’s suppose is something which we can compute in time, that is, instantly). Therefore, if is of order , this can be done on a regular machine. However, if , it may take, literally, ages for the algorithm to finish. For an algorithm of complexity , which scales with the square root of , should work. However let’s say you have in mind. Then either we find some algorithm with large enough or, even better, find a algorithm, which scales like . Roughly, if the algorithm works for , it should only take times more time to reach . Best of all, if you can find a direct formula for the sum, then you have an “instant” algorithm (whether this is instant or not depends on the formula you got…).

Maybe this could become more clear using some examples.

1. . The basic summation is time, but using the formula gives an algorithm. Basically, you can compute this sum for any you want by doing a couple of elementary operations.

2. Let’s complicate things a bit. What if is : the sum of all the divisors of ? First let’s note that computing alone is not immediately computable. One can imagine a basic algorithm, testing all integers if and summing them. If we know the factorization of we have a formula for in terms of prime factors and their powers. Prime factorization’s complexity is provided we have already made a sieve of primes (that’s other thing to think about). So we reach a complexity for . This is not enough if we want to sum things up to , for example. It turns out there’s a simple idea for a less complex algorithm.

We want to compute

Now what if we invert the sums? How do we do this? The summation indices satisfy . Thus, if we want to sum over instead of , then would be a multiple of all the time. So we find the alternative sum

where the last equality is valid since the number of multiples of less than is exactly . This already gives an complexity. Better than before, no factorizations involved, quite nice.

It turns out we can do even better. Looking at terms of the form we see that they take the same value multiple times. For example implies

Thus, summing on this interval we have

where the last sum has an explicit value since we sum consecutive terms of an arithmetic progression. Now we can switch to a summation over instead of . Note that we only need to go to high enough such that between and there is at least one integer. This is equivalent to so is . For larger than this value, we cannot guarantee the existence of an integer in our interval, so we’ll just compute the sums up to this and then sum the remaining terms which are again of order . This gives us a final algorithm.

Now, it is clear that if we need to compute our sum of sums of divisors up to , for example, only an algorithm like the last one can lead us to the result in reasonable time. Now you can solve Problem 401 in no time (replacing the sum of divisors with sum of squares doesn’t make much difference here, or does it?)

I hope this will motivate others to gain or regain interest in Project Euler problems. I solved over 120 problems in the last two months by learning to adapt algorithms and doing the necessary research when it is needed. Almost always, after solving a problem, you’ll find someone in the solution thread which has a better solution than yours. Look it up and continue improving your skills.

Project Euler problems don’t require only maths… Sometime more complex computer science stuff is needed. I learned the basics of dynamic programming and recursion solving some of the problems. I learned using lists, queues, combinatorial stuff, probabilities (still learning that though; lots of probability related stuff among PE problems). Not to mention that I learned to work quite well in some different languages, like Pari GP or Julia. It also forced me to compile and use some Java or Python codes.

It is a globally enriching quest: keep up with your maths, learn to do research online, improve programming skills, find new algorithms, choose right programming language to solve your problem efficiently, etc. It’s a hobby worth having.

]]>

To save you some time, here’s a picture of the case k=1 which I ignored and spent quite a lot of time debugging… Plus, it only affects the last three digits or so after the decimal point…

Here’s a Matlab code which can construct the pictures above and can compute the result for low cases. To solve the problem, you should compute explicitly all these areas.

function problem285(k) N = 100000; a = rand(1,N); b = rand(1,N); ind = find(abs(sqrt((k*a+1).^2+(k*b+1).^2)-k)<0.5); plot(a(ind),b(ind),'.'); axis equal M = k; pl = 1; for k=1:M if mod(k,100)==0 k end r1 = (k+0.5)/k; r2 = (k-0.5)/k; f1 = @(x) (x<=(-1/k+r1)).*(x>=(-1/k-r1)).*(sqrt(r1^2-(x+1/k).^2)-1/k).*(x>=0).*(x<=1); f1 = @(x) f1(x).*(f1(x)>=0); f2 = @(x) (x<=(-1/k+r2)).*(x>=(-1/k-r2)).*(sqrt(r2^2-(x+1/k).^2)-1/k).*(x>=0).*(x<=1); f2 = @(x) f2(x).*(f2(x)>=0); if k == pl thetas = linspace(0,pi/2,200); hold on plot(-1/k+r1*cos(thetas),-1/k+r1*sin(thetas),'r','LineWidth',2); plot(-1/k+r2*cos(thetas),-1/k+r2*sin(thetas),'r','LineWidth',2); plot([0 1 1 0 0],[0 0 1 1 0],'k','LineWidth',3); hold off axis off end A(k) = integral(@(x) f1(x)-f2(x),0,1); end xs = xlim; ys = ylim; w = 0.01; axis([xs(1)-w xs(2)+w ys(1)-w ys(2)+w]); sum((1:k).*A)

]]>

Now what happens if we add a little bit of wind? Here’s the perturbation obtained when adding a 10m/s uniform wind speed vs the initial configuration. Something like this would be a lot more challenging

]]>

satisfies

Show that is invertible.

**Problem 2.** Let .

- a) Prove that there exists such that for every the matrix equation
has a unique solution .

- b) Prove that if and is diagonalizable then

**Problem 3.** Let be a continuous function. Prove that

**Problem 4.** a) Let be an integer. Compute .

b) Let be a fixed integer and let be the sequence defined by

Prove that the sequence converges and find its limit.

**Source: **link

**Hints:** 1. This must be a joke We know that if for a norm matrix we have then is invertible. The sum of squares is a norm, so implies that is invertible.

2. The equation is . We know that there are at most values for when is not invertible (related to the eigenvalues of ). We have two cases. If one of the eigenvalues is zero, then pick smaller than the distance to the closest eigenvalue to . If is not an eigenvalue, then choose again smaller than the closest eigenvalue to . For note that and since and we get that . Since is diagonalizable we conclude that

Thus, multiplying by and letting go to zero we obtain for zero eigenvalues and zero for non-zero ones. Thus, the limit counts the number of zero eigenvalues, which is precisely (since is diagonalizable).

3. Classic SEEMOUS stuff. Prove that this works when , then extend to polynomials, and then, by density, to continuous functions. Proving this for monomial might get involved, but initial computations show that we have the same terms when performing the integrations by parts on the two sides…

4. coming…

]]>

Project Euler – problem 144 – visualization of the solution in Matlab

]]>

While searching a bit about the problem I did a brute force check to find the first such primes and I found the following values:

Since this was going nowhere I plugged these into the OEIS search engine and bam: it seems they are precisely the primes which can be written in the form . If this latter formulation holds, then the problem can be solved immediately, since searching for primes of the form is much easier than testing the first formula. Now how do we prove this? Suppose , which is equivalent, after simplifying , to

Note that we necessarily have . Now recall that is prime, so if divides we must have which is false, since a positive number cannot divide a number smaller than itself (I leave you the task of seeing why cannot be zero). Therefore it remains that and . Since and it follows that divides and . Therefore we can write

Multiply the first two relations and square the third to get . Furthermore, we have

so . Now let’s see what remains of the initial

Now let’s suppose that and denote . Then we have

Now let’s note that if is a common prime factor of and then it follows immediately that divides , contradicting the choice of above. Therefore we can assume that . This means that, for the above fraction to simplify we need to have . Furthermore, the ratio is strictly greater than . Moreover, so the previous fraction is in fact just . Since is prime, this forces the relation , which, since , gives us

Therefore and for some positive integer . In conclusion

Now if we have we can retrace the construction to find a the corresponding and . Note that in addition to we also have . Choosing we get exactly

]]>

There is a test case with 5 digits:

90342 ;2 correct

70794 ;0 correct

39458 ;2 correct

34109 ;1 correct

51545 ;2 correct

12531 ;1 correct

with unique solution 39542 and the difficult case with 16 digits

5616185650518293 ;2 correct

3847439647293047 ;1 correct

5855462940810587 ;3 correct

9742855507068353 ;3 correct

4296849643607543 ;3 correct

3174248439465858 ;1 correct

4513559094146117 ;2 correct

7890971548908067 ;3 correct

8157356344118483 ;1 correct

2615250744386899 ;2 correct

8690095851526254 ;3 correct

6375711915077050 ;1 correct

6913859173121360 ;1 correct

6442889055042768 ;2 correct

2321386104303845 ;0 correct

2326509471271448 ;2 correct

5251583379644322 ;2 correct

1748270476758276 ;3 correct

4895722652190306 ;1 correct

3041631117224635 ;3 correct

1841236454324589 ;3 correct

2659862637316867 ;2 correct

While the small case could be tackled using a pure brute force approach (only ) cases to check, the second case becomes intractable. Looping through all cases would take ages. One could try genetic algorithms or other algorithms based on randomness. Recursive approaches are also possible.

There is however a way to express this problem which makes it solvable right away using a linear programming solver: that is an algorithm which finds valid solutions given some constraints. How do we find these constraints? There are essentially two types of constraints in our case:

- each of the positions of the result contains one digit from 0 to 9
- in each of the guesses given above we have a fixed number of correct digits

We can model this in the following way: we define a matrix of size (number of digits from 0 to 9) times (number of digits of the result). At position (i,j) in this matrix we have 1 if the position j of the result contains the digit i-1 and zero otherwise. For example, the matrix corresponding to the result in the case of the 5 digit guess sequence 39542 is

Now, we can see clearer how can we impose the desired constraints. The fact that we have only one digit per position in the result is equivalent to the fact that on each column of the above matrix we have only one position equal to 1, or that the sum on the columns of the matrix is 1. This gives us as many constraints as digits in the solution. For example, the condition that in column 2 the sum is 1 can be written as

Now the conditions given by the current guesses are a bit different, but the idea is the same. For example the condition (90342 ;2 correct) can be translated to the following: in the set there are exactly 2 ones and three zeros. Therefore

Of course, this conditions can be found in an automatic way starting from the given guesses. This can be implemented in Matlab or Octave using linprog. If you have Yalmip installed then the setup is more straightforward, as illustrated in previous posts where I showed how to solve a Sudoku puzzle with Matlab or Two more mind games solved using Matlab.

]]>