Project Euler
by 담배맛구마[001] Multiples of 3 and 5
[002] Even Fibonacci numbers # 피보나치수열 홀짝되는 규칙찾으면 더빨라져
[003] Largest prime factor
[004] Largest palindrome product # 대칭수가 11의배수라는데?
[005] Smallest multiple
[006] Sum square difference # 시그마 공식 걍썼는데??
[007] 10001st prime # 내가 좀 멍청해서 브르투포스 # 224초였던가??
import time
t = time.time()
result = 0
for i in range(1, 100):
if(i % 3 == 0 or i % 5 == 0):
result += i
print("RESULT : " + str(result))
print("\n[RUNTIME :: %.02f]" % (time.time() - t))
import time
t = time.time()
result = 2 # Because curNum starts in 3, result is initiated by 2
first, second = 1, 2
curNum = 0
while curNum <= 4000000:
curNum = first + second
if(curNum % 2 == 0): result += curNum
first, second = second, curNum
print("RESULT : " +str(result))
print("\n[RUNTIME :: %.02f]" % (time.time() - t))
import time
t = time.time()
NUMBER = 600851475143
curPrime = 2
#Return Next Prime Number
def nextPrime(curPrime):
curPrime += 1
while 1:
for n in range(2, curPrime):
if(curPrime % n == 0):
curPrime += 1
break
elif(n == curPrime-1):
return curPrime
#main
while 1:
if(NUMBER % curPrime == 0): NUMBER /= curPrime
elif(NUMBER == 1): break
else: curPrime = nextPrime(curPrime)
print("The Largest Prime Factor : %d" % curPrime)
print("\n[RUNTIME :: %.02f]" % (time.time() - t))
import time
t = time.time()
cur = 0
result = 0
for a in range(100, 1000):
for b in range(100, 1000):
cur = a * b
if(cur < 100000):
if(int(cur/10000) == cur%10 and int(cur/1000)%10 == int(cur/10)%10):
if(result < cur): result = cur
else:
if(int(cur/100000) == cur%10 and int(cur/10000)%10 == int(cur/10)%10 and int(cur/1000)%10 == int(cur/100)%10):
if(result < cur): result = cur
print("RESULT : %d" % result)
print("\n[RUNTIME :: %.03f]" % (time.time() - t))
import time
t = time.time()
def nextPrime(curPrime):
curPrime += 1
while 1:
for n in range(2, curPrime):
if(curPrime % n == 0):
curPrime += 1
break
elif(n == curPrime-1):
return curPrime
ans, prime = 1, 2
list = []
for i in range(1, 21): list.append(i)
while(1):
notChange = 1
oneCount = 0
for i in range(0, 20):
if(list[i] % prime == 0):
list[i] = int(list[i] / prime)
notChange = 0
elif(list[i] == 1): oneCount += 1
if(oneCount == 20):
break
elif(notChange): prime = nextPrime(prime)
else: ans *= prime
print("ANS : %d" % ans)
print("\n[RUNTIME :: %f]" % (time.time() - t))
import time
t = time.time()
k = 100
sumOfSquares = int((k)*(k+1)*(2*k+1)/6)
squareOfSum = (int(k*(k+1)/2)) ** 2
ans = abs(sumOfSquares - squareOfSum)
print("ANS : %d" % ans)
print("\n[RUNTIME :: %.02f]" % (time.time() - t))
import time
t = time.time()
count = 1
curPrime = 2
while 1:
n = 2
while 1:
if(curPrime % n == 0):
curPrime += 1
break
elif(n == curPrime-1):
count += 1
print("%d %% %d [%d]" % (curPrime, n, count))
curPrime += 1
break
n += 1
if(count == 10001):
curPrime -= 1
break
print("ANS : %d" % curPrime)
print("\n[RUNTIME :: %.02f]" % (time.time() - t))
반응형
'Note' 카테고리의 다른 글
TCPDUMP로 웹 서비스 패킷을 이쁘게 찍어보자 (0) | 2021.09.05 |
---|---|
NTP(Network Time Protocol) (0) | 2018.07.29 |
Bootable DOS by CD For Firmware Update (2) | 2018.07.29 |
Chrom Offline Installer for Win32 (0) | 2017.09.11 |
파일 시스템 정리 (0) | 2017.08.16 |
블로그의 정보
정윤상이다.
담배맛구마