Please don't hate me for this

The base-10 conversion of nevergonnagiveyouup.nevergonnaletyoudown 36 \text{nevergonnagiveyouup.nevergonnaletyoudown}_{36} is equal to A B \dfrac{A}{B} where A A and B B are positive coprime integers. Find the sum of the digits of A + B . A+B.


The answer is 275.

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.

1 solution

Eek! How can I not hate you for this?

1
2
x=(Integer('nevergonnagiveyouupnevergonnaletyoudown'.upper(), base=36)/(36^len('nevergonnaletyoudown')))
sum((x.numerator()+x.denominator()).digits())

  • Press Evaluate

By the way, the exact answer is 3228155259133222787454466061098606354383456098128795960696151 13367494538843734067838845976576 \boxed{\frac{3228155259133222787454466061098606354383456098128795960696151}{13367494538843734067838845976576}}

For those who don't fully understand base conversions check out this simple yet comprehensive post on the topic by a fellow brilliant.org member.

Base Conversions

Cole Coupland - 6 years, 12 months ago

who about the dot? (".") Wouldn't that have no value in base 36?

DPK ­ - 6 years, 10 months ago

Why SageMath when we can do this simply using python?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from fractions import Fraction
ns=dict([(chr(i+48),i) for i in range(10)]+[(chr(i),i-87) for i in range(97,123)])
def decfrac(n,b):
    [p,q]=n.split('.')
    return sum(ns[p[-i]]*(b**(i-1)) for i in range(1,len(p)+1))+sum(ns[q[i]]*Fraction(1/Fraction(b**(i+1))) for i in range(0,len(q)))
base=int(input('Enter base = '))
text=input('Enter number in base %d = ' %base) #input must have a decimal point
m=decfrac(text,base)
print('\nExact form:\n\n',m)
print('\nSum of digits of numerator and denominator =',sum(int(i) for i in str(m.numerator+m.denominator)))

Here's the output:

Enter base = 36
Enter number in base 36 = nevergonnagiveyouup.nevergonnaletyoudown

Exact form:

 3228155259133222787454466061098606354383456098128795960696151/13367494538843734067838845976576

Sum of digits of numerator and denominator = 275

But yeah, the shorter Sage code looks much cooler.

Prasun Biswas - 5 years, 1 month ago

can you please explain me what's wrong with the following code,

 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
48
49
50
51
 from fractions import gcd

\boxed{
 str1='nevergonnagiveyouupnevergonnaletyoudown'

 i=len(str1)-1

 x=0

 c=1

 while(i>=0):

     x+=c*(10+ord(str1[i])-ord('a'))

     c*=36

     i-=1

 p =x

 q=36**20

 hc=gcd(p,q)

 cp=p//hc

 cq=q//hc



 sd=0

 s=cp

 while(s>0):

     sd+=s%10

     s//=10

 s  =cq

 while(s>0):

     sd+=s%10

     s//=10

 print(sd) 
} 

Aditya Mishra - 6 years, 8 months ago

Log in to reply

sorry for poor formatting :)

Aditya Mishra - 6 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...