Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:38:09+00:00 2026-05-28T16:38:09+00:00

I am currently trying out Project Euler and one of the question is calculate

  • 0

I am currently trying out Project Euler and one of the question is calculate 2^1000, and count the number of digits. I can easily do it for 2^15 but the issue with 2^1000 is that when I calculate it, it’s given in scientific notation, so it’s hard to sum the digits.

import math

def power(x):
    y_p=1000*math.log(x,10.0)
    y=math.pow(10,y_p)
    return y

if __name__=="__main__":

    ans=power(2)
    a=str(ans)
    print a
    sum=0

    for i in a:
       if i == ".":
          print "encountered ."
       elif i == "e":
          break
       else:
          sum=sum+int(i)

    print sum
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:38:10+00:00Added an answer on May 28, 2026 at 4:38 pm

    To calculate 2^1000 in Python use 2**1000. Using floating point functions like math.log and math.pow you are likely to get inaccurate results.

    Now, here is how to do it:

    l = str(2**1000)
    digits = [int(digit) for digit in l]
    print sum(digits)
    

    The first line converts the number to a string in base 10 representation.The second line iterates on the characters and transforms the string to a list of digits. And the third prints their sum.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My employer is currently trying out Fogbugz and one feature that would be nice
I am currently trying to figure out how you can bind multiple fields in
I am currently trying to figure out a way on how I can possibly
I'm currently trying to work through the Project Euler questions with Python (something I've
I'm currently working on an implementation of Project Euler problem 40 and am trying
I'm currently trying to solve problem 18 of project Euler . The goal is:
I've been trying to work my way through Problem 27 of Project Euler, but
I'm currently trying to push some of my project files to github but I've
I'm currently trying out Aptana Studio 3 for PHP development (I'm pretty new to
I am currently trying to figure out KendoUI. I am using version 2012.1.322. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.