-
2004) 조합 0의 개수 - Java백준코딩일기 2020. 1. 15. 21:38
https://www.acmicpc.net/problem/2004
123456789101112131415161718192021222324252627282930313233343536373839public class Main {public static void main(String[] args) throws IOException{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));String s = br.readLine();long n = Long.parseLong(s.split(" ")[0]);long r = Long.parseLong(s.split(" ")[1]);long two=0, five=0;if( r > (n/2) )r = n-r;for (long i=2; i<=n; i*=2) { // n! 에 포함된 2의 개수 합two += n/i;}for (long i=2; i<=n-r; i*=2) { // (n-r)! 에 포함된 2의 개수를 뺌two -= (n-r)/i;}for (long i=2; i<=r; i*=2) { // r! 에 포함된 2의 개수를 뺌two -= r/i;}for (long i=5; i<=n; i*=5) { // n! 에 포함된 5의 개수 합five += n/i;}for (long i=5; i<=n-r; i*=5) { // (n-r)! 에 포함된 5의 개수를 뺌five -= (n-r)/i;}for (long i=5; i<=r; i*=5) { // r! 에 포함된 5의 개수를 뺌five -= r/i;}}} cs'백준코딩일기' 카테고리의 다른 글
11727) 2×n 타일링 2 - Java (0) 2020.01.24 11726) 2×n 타일링 - Java (0) 2020.01.24 10872) 팩토리얼 - JAVA (0) 2020.01.15 1676) 팩토리얼 0의 개수 - JAVA (0) 2020.01.15 1158) 조세푸스 문제 - JAVA (0) 2020.01.06