Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Laminar
- 유체역학
- Fluids
- 힙
- 프로젝트오일러
- Python
- Finite Difference Method
- Fluid Dynamics
- Navier-Stokes
- 회귀
- 파이썬
- 프로그래머스
- Turbulent
- Boundary Layers
- projecteuler
- 통계학
- 디스크 컨트롤러
- FTCS
- Crank-Nicolson
- python3
- 예제
- 이중우선순위큐
- Heat Equation
- heap
- 우선순위큐
- Blasius
- Statistics
- Compressible Flow
- programmers
- regression
Archives
- Today
- Total
Sudal's Garage
Project Euler 20 본문
Question:
n! means n × (n − 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find the sum of the digits in the number 100!
문제:
n! 이라는 표기법은 n × (n − 1) × ... × 3 × 2 × 1을 뜻합니다.
예를 들자면 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800 이 되는데,
여기서 10!의 각 자리수를 더해 보면 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27 입니다.100! 의 자리수를 모두 더하면 얼마입니까?
Solution:
1 2 3 4 5 | from math import factorial import time start = time.time() print(eval("+".join(list(str(factorial(100)))))) print('Found in ... {:.5f}s'.format(time.time() - start)) | cs |
100! 을 string 으로 만든 후, list 처리를 하고 join을 이용하여 사이사이에 +를 넣어주고 eval 함수를 써주었다.
eval 함수는 여기서도 썼었다.
2019/03/03 - [Programming/Project Euler - python] - Project Euler 16
0.0003s 걸렸다!
'Programming > Project Euler - python' 카테고리의 다른 글
Project Euler 22 (0) | 2019.03.10 |
---|---|
Project Euler 21 (0) | 2019.03.09 |
Project Euler 19 (0) | 2019.03.07 |
Project Euler 18 (0) | 2019.03.06 |
Project Euler 17 (0) | 2019.03.05 |