63.py 716 B

123456789101112131415161718192021222324
  1. # Global variable for number of n-digit positive integers exist which are also an nth power
  2. powerful = 0
  3. for power in range(1,100):
  4. # Create upper and lower bounds for the number of digits
  5. lowerbound = 10**(power-1)
  6. upperbound = 10**power
  7. # Counter variables
  8. counter = 1
  9. currentpower = 1
  10. while currentpower < upperbound:
  11. currentpower = counter**power
  12. # Optional status indicators for testing - not intended for production
  13. # print "Current value of expression: " + str(currentpower)
  14. # print "Bounds are from " + str(lowerbound) + " < x < " + str(upperbound)
  15. if currentpower >= lowerbound and currentpower < upperbound:
  16. print counter**power
  17. powerful += 1
  18. counter += 1
  19. print powerful