#Playing with numbers-3

A function F b ( x ) F_b(x) gives the sum of the digits of a decimal non-negative integer x x after converting it into base b b . Such as F 2 ( 6 ) = 2 F_2(6)=2 ,the sum of the digits of the binary of 6,110. Find the lowest 5 digit number X X for which F 3 ( X ) = 14 F_3(X)=14 and F 7 ( X ) = 20 F_7(X)=20 .

Here are the previous problems of the series :

#Playing with numbers-1

#Playing with numbers-2


The answer is 10610.

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.

3 solutions

Rafsan Rcc
May 10, 2021

I used the following codes

 1
 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
#include<stdio.h>
#include<math.h>

unsigned long int convert(unsigned long int number,int base);
unsigned long int F(unsigned long int number,int base);

int main()
{   unsigned long int i,q;
    i=10000;
    q=1;
    do{
        if(F(i,3)==14 && F(i,7)==20)
        {printf("%lu\n",i);
         q=0;}
        i+=1;
    }
    while(q!=0);
}

//convert function takes a decimal number and converts it to another base
unsigned long int convert(unsigned long number,int base)
{
    unsigned long int n,result;
    int i;
    i=0;
    n=number;
    result=0;
    do{result+=(n%base)*pow(10,i);
    n-=(n%base);
    n/=base;
    i+=1;}
    while(n>0);
    return result;
}

//The function F is similar to the one given in the question
unsigned long int F(unsigned long int number,int base)
{   unsigned long int result,n,i,x;
    result=0;
    x=convert(number,base);
    n=x;
    for(i=0;i<=log(x);i++)
    {result+=n%10;
    n-=n%10;
    n/=10;}
    return result;
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#F function finds the sum of the digits of a number converted to a base<=10
def F(number,base):
    result=[]
    n=number
    while n>0 :
        result.append(n%base)
        n//=base
    sum=0
    for i in result:
        sum+=i
    return sum

i=10000
q=1
while q!=0:
    if(F(i,3)==14 and F(i,7)==20) :
        print(i)
        q=0
    i+=1

Kunal Gupta
May 16, 2021
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def convert_to_base_b_and_return_sum(x, b):
    ans = 0
    while x!=0:
        ans+=x%b
        x = x//b
    return ans

x = 10000
while x<1000000:
    if convert_to_base_b_and_return_sum(x, 3) == 14 and convert_to_base_b_and_return_sum(x, 7) == 20:
        break
    x+=1
print(x)

Fletcher Mattox
May 10, 2021
1
2
3
4
5
from baseconvert import base
n = 10000
while not (sum(base(n, 10, 3)) == 14 and sum(base(n, 10, 7)) == 20):
    n += 1
print(n)

1
10610

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...