A quick program in sage math to calculate number of 1s in first n natural numbers

n =20
counter=0
for i in range(n):
    count=0
    if(is_prime(i)):
        j=str(i)
        for k in j:
            if k=='1':
                count=count+1
        if counter == i:
            print(i,counter)
        
    counter = count+counter
print(i,counter)

About Sumant Sumant

I love Math and I am always looking forward to collaborate with fellow learners. If you need help learning math then please do contact me.
This entry was posted in Computer Program, Prime Numbers and tagged . Bookmark the permalink.

Leave a comment