Project Euler #80: Square root digital expansion

  • + 0 comments

    My Solution in python

    from decimal import Decimal,getcontext def sum_of_digits(n,p): getcontext().prec=p+5 sqrt_str=str(Decimal(n).sqrt()).replace('.','')[:p] return sum(int(digit) for digit in sqrt_str) def main(): N= int(input().strip()) P= int(input().strip()) total_sum= sum(sum_of_digits(i,P) for i in range (1,N+1) if int (i**0.5)**2 != i) print(total_sum) if name=="main": main()