CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 10:35:08 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=7c34e6b34f0ef5cc07efef9395b4be0db75993280b1fe28cf1d2456fa23afd39a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%225zR6pzkLUQBvOAMzQbjXKZv-g8Du8SDd%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cdb5824f94c1d2-BLR
Project Euler, Problem #12, Python - Pastebin.com
SHARE
TWEET

Project Euler, Problem #12, Python
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The sequence of triangle numbers is generated by adding the natural
- # numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 +
- # 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36,
- # 45, 55, ... Let us list the factors of the first seven triangle
- # numbers: 1: 1; 3: 1, 3; 6: 1, 2, 3, 6; 10: 1, 2, 5, 10; 15: 1, 3, 5,
- # 15; 21: 1, 3, 7, 21; 28: 1, 2, 4, 7, 14, 28 We can see that 28 is
- # the first triangle number to have over five divisors. What is the
- # value of the first triangle number to have over five hundred
- # divisors?
- # Version 1: slightly shorter and faster
- cntr = 2
- ctn = 1
- dn = 0
- while True:
- ctn += cntr
- md = int(ctn ** 0.5)
- if md < ctn ** 0.5:
- cv = 0
- else:
- cv = 1
- if ctn % 2 == 0:
- dn = sum([2 if ctn % x == 0 else 0 for x in range(1, md + 1)])
- else:
- dn = sum([2 if ctn % x == 0 else 0 for x in range(1, md + 1, 2)])
- if dn - cv > 500:
- break
- dn = 0
- cntr += 1
- print(ctn)
- # 76576500
- # 24752 function calls in 9.839 seconds
- # Version 2
- cntr = 2
- ctn = 1
- dn = 0
- while True:
- ctn += cntr
- md = int(ctn ** 0.5)
- if md < ctn ** 0.5:
- cv = 0
- else:
- cv = 1
- if ctn % 2 == 0:
- for d in range(1, md + 1):
- if ctn % d == 0:
- dn += 2
- else:
- for d in range(1, md + 1, 2):
- if ctn % d == 0:
- dn += 2
- if dn - cv > 500:
- break
- dn = 0
- cntr += 1
- print(ctn)
- # 76576500
- # 12376 function calls in 10.944 seconds
Advertisement
Add Comment
Please, Sign In to add comment
-
✅⭐ Make huge profits on trading ⭐⭐ 6
JavaScript | 2 sec ago | 0.24 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 2 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 11 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ 9
JavaScript | 12 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ D
JavaScript | 20 sec ago | 0.24 KB
-
⭐⭐⭐ G2A Payment Exploit ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 22 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 31 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 5
JavaScript | 31 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand