#Playing with numbers-2

A positive integer has a property Y Y if the sum of the squares of its digits is coprime with the number. The probability that a number not more than 2 × 1 0 6 2\times10^6 will have that property is x % x\% . Enter x x .

Here is #Playing with numbers-1


The answer is 62.16125.

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

Fletcher Mattox
May 10, 2021

The correct answer is 62.01115, not what the author of the problem specified.

1
2
3
4
5
6
from math import gcd

count = 0
for n in range(1, 2*10**6 + 1):
    count += gcd(n, sum(list(map(lambda i:i**2, list(map(int,list(str(n)))))))) == 1
print(count/(2*10**6) * 100)

1
62.01115

Even I got the same number!

Kunal Gupta - 3 weeks, 6 days ago

His answer is wrong. But it's close enough to the correct answer that Brilliant rounding conveniently honors the correct answer as well.

Fletcher Mattox - 3 weeks, 6 days ago
Rafsan Rcc
May 9, 2021

Here are the codes that I used.

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

unsigned long int coprime(unsigned long int x,unsigned long int y);
unsigned long int sum(unsigned long int x);

int main()
{ unsigned long int result,i;
  result=0;
  for(i=1;i<=2000000;i++)
  {result+=sum(i);}
  printf("\nTotal : %lu",result);
}

//coprime(x,y) returns 1 if x and y are coprime,otherwise 0
unsigned long int coprime(unsigned long int x,unsigned long int y)
{int i;
 int result=1;
 for(i=2;i<=x;i++)
 {if(x%i==0 && y%i==0) {result=0;break;};}
 return result;}

 //sum finds the sum of the squares of the digits of x and returns 1 if that sum is coprime with x,otherwise returns 0
unsigned long int sum(unsigned long int x)
{ unsigned long int s,n,i;
    s=0;
    n=x;
    for(i=0;i<=log(x);i++)
    {s+=pow(n%10,2);
    n-=n%10;
    n/=10;}
    if (coprime(s,x)==1) return 1;
    else return 0;
}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#coprime(x,y) returns 1 if x and y are coprime,otherwise 0
def coprime(x,y):
    r=1
    for i in range(2,x+1):
        if(x%i==0 and y%i==0) :
            r=0
            break
    return r

#sum finds the sum of the squares of the digits of x and returns 1 if that sum is coprime with x,otherwise returns 0
def sum(x):
    result=0
    for i in str(x):
        result+=int(i)**2
    if coprime(result,x)==1 : return 1
    else : return 0

a=0
for i in range(1,2000001):
    a+=sum(i)
print("\nTotal : ",a)

@Rafsan Rcc I think your coprime function is broken. For example, it claims 2 and 4 are coprime.

1
2
3
4
5
6
7
8
9
def coprime(x,y):
    r=1
    for i in range(2,x//2+1):
        if(x%i==0 and y%i==0) :
            r=0
            break
    return r

print(coprime(2, 4))

1
1

Fletcher Mattox - 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...