[파이썬][백준 15439번] Vera and Outfits
1. 문제Permalink
[Bronze V] Vera and Outfits - 15439Permalink
성능 요약Permalink
메모리: 30864 KB, 시간: 72 ms
분류Permalink
사칙연산(arithmetic), 조합론(combinatorics), 수학(math)
문제 설명Permalink
Vera owns N tops and N pants. The i-th top and i-th pants have colour i, for 1 ≤ i ≤ N, where all N colours are different from each other.
An outfit consists of one top and one pants. Vera likes outfits where the top and pants are not the same colour.
How many different outfits does she like?
입력Permalink
The input will be in the format:
N
Constraints:
- 1 ≤ N ≤ 2017
- N is integer
출력Permalink
Output one line with the number of different outfits Vera likes.
출처: 백준, https://https://www.acmicpc.net/
2. 해결방법 시간복잡도Permalink
- 단순 코딩 O(1)
3. 문제 해결 및 코드Permalink
N = int(input()) | |
if N > 1: | |
print(N * (N-1)) | |
else: | |
print(0) |
-
주석을 참고하면서 이해를 돕습니다.Permalink
4. 알고리즘 및 해설Permalink
- 받은 값이 1보다 작을 경우에는 0을 출력해주고, 0보다 크다면 해당 값을 해당값 - 1을 곱한뒤 출력한다.