[백준] 2004번 : 조합 0의 개수 - Java(자바)

강재원·2022년 10월 21일
0

[코딩테스트] Java

목록 보기
138/200



https://www.acmicpc.net/problem/2004

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int m=s.nextInt();
        int count2=0;
        int count5=0;
        for(long i=2;i<=n;i*=2) count2+=n/i;
        for(long i=2;i<=m;i*=2) count2-=m/i;
        for(long i=2;i<=n-m;i*=2) count2-=(n-m)/i;
        
        for(long i=5;i<=n;i*=5) count5+=n/i;
        for(long i=5;i<=m;i*=5) count5-=m/i;
        for(long i=5;i<=n-m;i*=5) count5-=(n-m)/i;
        
        System.out.format("%d",count2<=count5 ? count2 : count5);
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글