본문 바로가기

problem solving

Problem 8 - Discover the largest product of five consecutive digits in the 1000-digit number. 링크 Find the greatest product of five consecutive digits in the 1000-digit number. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 3035890729.. 더보기
Problem 7 - Find the 10001st prime. 링크 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? python def isprime(n): if n & 1 == 0: return False for x in range(3, int(n**0.5)+1, 2): if n % x == 0: return False return True count = 1 n = 2 while count < 10001: n = n + 1 if isprime(n): count = count + 1 print n python - speed up def isprime(n): if n == 1:.. 더보기
Problem 6 - What is the difference between the sum of the squares and the square of the sums? 링크 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640. Find the difference between the sum of the squares of the first one hundred natural nu.. 더보기
Problem 5 - What is the smallest number divisible by each of the numbers 1 to 20? 링크 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest number that is evenly divisible by all of the numbers from 1 to 20? We think of the sequence n_p = as a number system for positive integers. For example, the prime-exponent representation of 12 is and of 18 is To multiply two numbers, we simply add their representati.. 더보기
Problem 4 - Find the largest palindrome made from the product of two 3-digit numbers. 링크 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99. Find the largest palindrome made from the product of two 3-digit numbers. python ans = 0 for i in range(100, 1000): for j in range(i, 1000): n = i * j sn = str(n) if sn == sn[::-1] and n > ans: ans = n print ans python - 1 line print max([x*y for x in range(900,1.. 더보기
Problem 3 - Find the largest prime factor of a composite number. 링크 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? python n = 600851475143 d = 3 ans = 0 while n > 1: while n % d == 0: n = n / d ans = d d = d + 2 print ans bash Shell echo 600851475143|factor 더보기
Problem 2 - Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million. 링크 Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million. python a = 0 b = 1 res = 0 while a 더보기
Problem 1 - Add all the natural numbers below one thousand that are multiples of 3 or 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. python 1 sum = 0 for i in range(1, 1000): if i % 3 == 0 or i % 5 == 0: sum += i print sum python 2 print sum([x for x in range(1000) if x % 3 == 0 or x % 5 == 0]) 더보기
TopCoder - SRM 몽땅 풀기 Single Round Match 몽땅풀기 1 단계: Div2 Level 1 & Level 2 다 풀기 진행중... 1 단계: Div2 다풀기 진행중... 1 단계: Div1 Div2 다 풀기 진행중 어느 천년에 다푸나... ㅠㅠ SRM# Div1 Div2 Level 1 Level 2 Level 3 Level 1 Level 2 Level 3 144 System Fail 296.70 / 550 System Fail 197.72 / 200 443.35 / 550 741.64 / 1100 145 239.66 / 250 477.70 / 500 739.20 / 1100 combinatorics 146 246.69 / 250 497.35 / 500 814.65 / 1000 bridge crossing 147 248.. 더보기
TopCoder - SRM 몽땅 풀기 ( 노트 ) SRM 158 - Div2 Level2 (500 point) +=형식의 식이 주어지면 2~20진수 수체계 중 이 식을 만족하는 base를 찾아서 리턴하는 것이 문제였는데, 테스트케이스 0+0=0 에서 1,2,3, ... , 20 을 리턴해버렸음. 세상에 1진수라니 ㄷㄷㄷ.... SRM 159 - Div2 Level 2 (500 point) 배열(혹은 set)의 합집합, 교집합, 합집합-교집합 구하기 합집합: set_union(A.begin(), A.end(), B.begin(), B.end(), back_inserter(C)); 교집합: set_intersection(A.begin(), A.end(), B.begin(), B.end(), back_inserter(C)); 합집합-교집합: set_symme.. 더보기