Not Vieta's

N N is a natural number between 10 and 1000. P P denotes the product of its digits and S S denotes the sum of its digits. If ( 6 × P ) + ( 4 × S ) = 4 × N (6 \times P ) + (4 \times S ) = 4 \times N , how many values can N take ?

You can try more of my Questions here .


The answer is 11.

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.

5 solutions

Brock Brown
Dec 29, 2014
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def s(x):
    total = 0
    for digit in str(x):
        total += int(digit)
    return total
def p(x):
    product = 1
    for digit in str(x):
        product *= int(digit)
    return product
n = 10
count = 0
while n <= 1000:
    if 6*p(n) + 4*s(n) == 4*n:
        count += 1
    n += 1
print "Answer:", count

The values that N can take are 16, 26, 36, 46, 56, 66, 76, 86, 96, 889, and 998.

just like i did it.

you could use

def s(x):
        return sum ([int(c) for c in str(x)])

Ori Ashual - 6 years, 2 months ago

Log in to reply

Yeah, you're right, that's the way better version of the digit sum function. I wrote that code before I was familiar with list comprehensions .

Brock Brown - 6 years, 2 months ago

Log in to reply

Also, for product of digits, you can do reduce(operator.mul, (int(t) for t in str(x)), 1) . By the way, you need to import operator .

Arulx Z - 5 years, 11 months ago
Bill Bell
Jul 2, 2015
  • Number can be split into its integers using Python's map and list functions.
  • reduce can be used in conjunction with a lambda function to compute the product needed.
  • Conditional incrementation of counter can be done with predicate based on required condition.

Aryan Gaikwad
Apr 3, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public static void main(String args[]){
    int val = 0;
    for(int n = 11; n < 1000; n++)
        if(mul(Integer.toString(n)) + add(Integer.toString(n)) == 4 * n)
            val++;
    System.out.println(val);
}

private static int add(String n){
    int sum = 0;
    for(int i = 0; i < n.length(); i++)
        sum += Character.getNumericValue(n.charAt(i));
    return sum * 4;
}

private static int mul(String n){
    int prod = 1;
    for(int i = 0; i < n.length(); i++)
        prod *= Character.getNumericValue(n.charAt(i));
    return prod * 6;
}

I use Python coding as follows:

n = 0
for N in range(10,1001):
  T = str(N)
  P = 1
  S = 0
  for i in range(len(T)):
      P *= int(T[i])
      S += int(T[i])
  if 6*P + 4*S == 4*N:
      n += 1
      print n, P, S, N
Arulx Z
Jul 18, 2015
1
2
3
4
import operator
n = 0
for x in xrange(11, 1000):
    n += (6 * reduce(operator.mul, (int(t) for t in str(x)), 1)) + (4 * sum(int(z) for z in str(x))) == 4 * x

Moderator note:

A good solution. Consider breaking the statement inside the for loop up into a few more statements. It's good coding practice to have one major operation take place per line.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...