The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
p12
Posted by: ioni | April 18, 2010 @ 4:51pm
Python Code
[
Download
]
import math from math import * def p12d(int1): # based on factorization # http://answers.yahoo.com/question/index?qid=20071208133532AAPW5Q7 # i and tri are for advancing the triangular number i = 1 tri = 1 factors = 1 # loop until there are more than int1 factors while factors <= int1: factors = 1 ########## # Calculate the number of factors that tri has. prime = 1 temp = tri # STOP WHEN PRIME IS BIGGER THAN TRIANGLE: while prime <= tri: # GENERATE THE NEXT PRIME prime = prime + 1 primestat = True rangel = int(sqrt(prime)) + 1 for item in range(rangel, 1, -1): if prime % item == 0: primestat = False break # IF YOU GET A PRIME if primestat == True or prime == 2: # DIVIDE AS MANY TIMES AS POSSIBLE t = 1 while temp % prime == 0: temp = temp / prime t += 1 factors *= t ########## # keep together i += 1 tri += i # when done, what is the triangle number that meets requirements? return tri - i
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.26 / 8
54 Votes
http://codebin.yi.org/594
page generated in 0.00 seconds