Actually, according to stats this one should be relatively hard. However, it can be solved very easily. Probabably, this shows that either people are not good at solving probability problems or they do not like to solve them. Who knows? Here is my code in python. Runs under 1 second.
?View Code PYTHON1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import decimal
pdict={}
cdict={}
pcount=0
ccount=0
for i in [...]
This one was not hard at all. What I did was to have a while loop for each integer that has an irrational square root. The loop breaks when the sequence goes into a repetition. I have several variables to keep track of the parts in the expression. I use tuples to store the expression [...]
Show Problem
Here is the mathematical analysis of the problem:
There are no 1-digit solutions. You can verify it easily. If you add any digit with itself whether odd or even it becomes an even digit or a number wit an even digit.
For ab to be a two-digit solution, a+b must be odd and less than 10, [...]
Show Problem
I used a simple bruteforce to solve this problem. Thus, it takes about 2 minutes to find the answer.
?View Code PYTHON1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from math import sqrt
primes={}
for i in range (2,10000):
primes[i]=True
def prime(n):
i=2
while(i<sqrt(n)+1):
if n%i==0:
return False
i=i+1
return True
def test(one,two):
if prime(int(str(one)+str(two))) and prime(int(str(two)+str(one))):
return True
return False
for [...]
Show Problem 61
This gave me a headache. I was about to give up when I recalled that recursion is a very powerful tool and is very suitable for this question. The code does not look so pretty or concise but it is really powerful. I think you can figure out easily what I tried to [...]
Finally, I have found a very efficient answer for Problem 72. It runs under 1 seconds. It uses prime sieve of Eratosthenes.
Here is the code in Java
?View Code JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Arrays;
public class Problem72 {
public static void main(String args[])
{
int n=1000000;
int[] phi = new int[n+1];
for (int i=0; i<n+1; i++)
phi[i]=i;
boolean[] p = new boolean[n+1];
Arrays.fill(p, true);
p[0]=false;
p[1]=false;
for (int i=2; i<=n; i++)
{
if [...]
Show Problem 72
This code took about 30 minutes to run on my computer. I tried to implement the same logic in Java; however, it took hours to get an answer.However, an efficient Java solution with prime sieving is HERE.(Runs under 1 seconds). Here is the logic the totient function of a number gives how many [...]
Show Problem 102
First of all we need a method to check whether a point is in the triangle or not. This site has some useful info regarding this issue. Actually, it is for three dimension but two dimensions is applicable if we set the third dimension to zero always. All we need to code is [...]
Show Problem 62
For this one I used a map. I calculated the cubes for integers till 10000. Then I sorted every cube. Using a hashmap I calculated the frequency of each sort. If the freq is 5, that gives us the combination. Using another hashmap I associated the integer before cube calculation with the combination. [...]
Show Problem 112
This one is very easy if you know the trick. Here is the trick. If you sort a number ascendingly and if it is still equals the same number then it is an increasing one. If you sort it descendingly and is still the same number it is a decreasing one. If neither [...]