Luogu P1008 - Triple hit

This problem has no inputs, and both mental calculation or programming are acceptable.

If 1 , 2 , , 9 1,2,\cdots,9 were split into 3 3 disjoint groups and we use them to make three 3 3 -digit numbers x , y , z x,y,z , such that x : y : z = 1 : 2 : 3 x:y:z=1:2:3 , then find all possible triples for ( x , y , z ) (x,y,z) .

How to submit:

Find all possible triples for ( x , y , z ) (x,y,z) , and submit ( x + 2 y + 4 z ) \displaystyle \sum (x+2y+4z) .


Luogu Problem Set


The answer is 17187.

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.

2 solutions

Sahil Goyat
Oct 28, 2020
1
sum([17*x for x in range(100,1000) if len(set([i for i in str(x)+str(2*x)+str(3*x) if i!='0']))==9 and len(str(3*x))==3])

David Vreken
Jul 20, 2020

The following Python code tests all possible groupings and outputs 17187 \boxed{17187} .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Triple Hit
# Python

from itertools import permutations 

p = list(permutations(range(1, 10))) 
total = 0

for a in range(0, len(p)):
    x = p[a][0] * 100 + p[a][1] * 10 + p[a][2]
    y = p[a][3] * 100 + p[a][4] * 10 + p[a][5]
    z = p[a][6] * 100 + p[a][7] * 10 + p[a][8]
    if y == 2 * x and z == 3 * x:
        total += (x + 2 * y + 4 * z)

print(total)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...