#Playing with numbers-4.

A number is said to have a property Z b Z_b if that number is divisible by the number of segments needed to display the number in a 7-segment display after converting the number in base b. For example : ( 57 ) 10 = ( 2010 ) 3 (57)_{10}=(2010)_3 and 2010 needs 19 segments to be displayed so 57 has the property Z 3 Z_3 . If the lowest 5-digit numbers having properties Z 3 Z_3 and Z 9 Z_9 are respectively x 3 x_3 and x 9 x_9 , enter x 9 x 3 x_9-x_3 .

For the previous problem : #Playing with numbers-3


The answer is 2.

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

Rafsan Rcc
May 10, 2021
 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 segment(unsigned long int number);

int main()
{
    unsigned long int i;
    i=10000;
    do
    {i+=1;
    }while(i%segment(convert(i,3))!=0);
    printf("x3=%lu\n",i);
    i=10000;
    do
    {i+=1;
    }while(i%segment(convert(i,9))!=0);
    printf("x9=%lu",i);
 }
//segment returns the number of segments to display number
unsigned long int segment(unsigned long int number)
{   unsigned long int result,n;
    int s[10]={6,2,5,5,4,5,6,4,7,6};
    n=number;
    do
    {result+=s[n%10];
     n-=n%10;
     n/=10;
    }while(n>0);
    return result;
}

unsigned long int convert(unsigned long int 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;
}

 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
def segment(x):
    seg=[6,2,5,5,4,5,6,4,7,6]
    result=0
    for i in x:
        result+=seg[int(i)]
    return result

def convert(number,base):
    result=[]
    n=number
    while n>0:
        result.append(n%base)
        n//=base
    result.reverse()
    r=""
    for i in result:
        r+=str(i)
    return r

i=10000
while i%segment(convert(i,3))!=0:
    i+=1
print("x3=",i)
i=10000
while i%segment(convert(i,9))!=0:
    i+=1
print("x9=",i)

Kunal Gupta
May 16, 2021
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def get_segments(x):
    arr = [6, 2, 5, 5, 4, 5, 6, 4, 7, 6]
    return arr[x]

def convert_to_base_b_and_return_sum(x, b):
    ans = 0
    while x!=0:
        ans+=get_segments(x%b)
        x = x//b
    return ans

def getzb(b):
    x = 10000
    while True:
        if(x%convert_to_base_b_and_return_sum(x, b)==0):
            return x
        x+=1

print (getzb(9)-getzb(3))

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...