최대 소인수 600851475143의 소인수 중에서 최대 값을 구하라. """ Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? """ class PrimeNumber: def __init__ ( self ): self .current = 1 self .num_set = set () def __iter__ ( self ): return self def __next__ ( self ): self .current += 1 while True : for i in self .num_set: if self .current % i == 0 : self .current += 1 break # Break current for loop else : break # Break the while loop and return self .num_set.add( self .current) return self .current if __name__ == '__main__' : number = 600851475143 prime_number = PrimeNumber() for n in prime_number: if n > number: break if number % n == 0 : print (n) https://projecteuler.net/proble
#!/ usr /bin/python3 # 가장 기본적인 메인 스크립트 템플릿 # by Elex (http://python.elex.pe.kr/) def main (): print ( "Hello" ) if __name__ == "__main__" : main() 파이썬 스크립트의 맨 첫 줄에는 파이썬 인터프리터의 경로를 지정한다. 현재 스크립트가 메인 모듈로써 실행되는 경우에는 __name__ 변수의 값이 "__main__"이 된다. 따라서, 이 스크립트는 메인 모듈로써 실행되는 경우에만 main() 함수를 처리하게 된다.
3과 5의 배수 1000 미만의 자연수 중, 3과 5의 배수의 합을 구하라. https://projecteuler.net/problem=1 """ Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. """ if __name__ == '__main__' : s = 0 for i in range ( 1 , 1000 ): if i % 3 == 0 or i % 5 == 0 : s += i print (s)
댓글
댓글 쓰기