The Cleverer Cat?

Computer Science Level pending

How many slices of the list used in this problem multiply to get a prime less than or equal to 31?

This problem is inspired by Agnishom Chattopadhyay who was inspired by Christopher Boo , who in turn was inspired by the Malaysia Computing Olympiad 2014.


The answer is 177.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

David Holcer
Apr 10, 2015

Solution very similar to solution on clever cat, this time replacing sum with prod to get product. Counting occurrences and returning. Read comments on clever cat for clarification.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def is_prime(a):
    return a > 1 and all(a % i for i in xrange(2, a))

#array=[set of number]
def totall(array,num):
    total=0
    for n in xrange(1,len(array)+1):
        for i in xrange(len(array)):
            cur=array[i:i+n]
            if len(cur)==n:
                prod=1
                for i in cur:
                    prod*=i
                if prod<=num and is_prime(prod): total+=1
    return total
print totall(array,31)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...