From 60ec25ef7a1f0294c066eaba568011752727f7c7 Mon Sep 17 00:00:00 2001 From: Sanders Lin <45224617+SandersLin@users.noreply.github.com> Date: Fri, 7 Dec 2018 02:29:04 +0800 Subject: [PATCH] Update sol1.py --- project_euler/problem_12/sol1.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project_euler/problem_12/sol1.py b/project_euler/problem_12/sol1.py index 9c4483fd6..73d48a2ec 100644 --- a/project_euler/problem_12/sol1.py +++ b/project_euler/problem_12/sol1.py @@ -30,7 +30,9 @@ def count_divisors(n): for i in xrange(1, int(sqrt(n))+1): if n%i == 0: nDivisors += 2 - + #check if n is perfect square + if n**0.5 == int(n**0.5): + nDivisors -= 1 return nDivisors tNum = 1 @@ -43,4 +45,4 @@ while True: if count_divisors(tNum) > 500: break -print(tNum) \ No newline at end of file +print(tNum)