๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm

[Algorithm/Java][๋ฐฑ์ค€] 1676๋ฒˆ ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜

๋ฐ˜์‘ํ˜•

[๋ฐฑ์ค€] 1676๋ฒˆ ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜

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

๋ฌธ์ œ์ ‘๊ทผ

์ฒ˜์Œ์—๋Š” ๊ทธ๋ƒฅ ํŒฉํ† ๋ฆฌ์–ผ ์žฌ๊ท€ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๋‹จ์ˆœํ•˜๊ฒŒ 0์˜ ๊ฐœ์ˆ˜๋ฅผ ์…€๋ ค๊ณ  ํ–ˆ๋‹ค. ๊ทผ๋ฐ ์ž…๋ ฅ์˜ ๋ฒ”์œ„๊ฐ€ 500๊นŒ์ง€ ์˜€๊ณ  500!๋Š” long์œผ๋กœ๋„ ์ปค๋ฒ„๊ฐ€ ๋˜์ง€ ์•Š๋Š” ๋ฒ”์œ„์˜€๋‹ค. ๊ทธ๋ž˜์„œ ๊ฒ€์ƒ‰์„ ํ•ด๋ณธ ๊ฒฐ๊ณผ!@! ๋งจ ๋’ค์—์„œ ์—ฐ์†๋˜๋Š” 0์˜ ๊ฐœ์ˆ˜๋ฅผ ์„ผ๋‹ค๋Š” ๊ฒƒ์€ 2 * 5 ์˜ ๊ฐฏ์ˆ˜๊ฐ€ ๋ช‡๊ฐœ๊ฐ€ ์žˆ๋Š”์ง€์™€ ๊ฐ™๋‹ค!!๋ผ๋Š” ์—„์ฒญ๋‚œ ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์–ด์„œ ์ด๋ฅผ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋‹ค....๋Œ€๋ฐ•...

Code

import java.util.Scanner;

public class BOJ1676 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int twoCnt = 0;
        int fiveCnt = 0;
        for(int i = 2; i<=num; i++){
            int n = i;
            while(n % 2 == 0){
               twoCnt++;
               n /= 2;
            }
            while(n % 5 == 0){
                fiveCnt++;
                n /= 5;
            }
        }
        int cnt = Math.min(twoCnt,fiveCnt);
        System.out.println(cnt);
    }
}

์–ด๋ ค์› ๋˜ ์  / ๋ฐฐ์šด ์  / ๋Š๋‚€ ์ 

500!์ด ์—„์ฒญ๋‚œ ์ˆ˜์˜€๋‹ค๋Š”๊ฒƒ์„ 3๋ฒˆ์ด๋‚˜ ํ‹€๋ ธ์„ ๋•Œ ๊นจ๋‹ฌ์•˜๋‹ค... 2 * 5์˜ ๊ฐฏ์ˆ˜์ผ ์ค„์€ ์ƒ๊ฐ๋„ ๋ชปํ–ˆ๋Š”๋ฐ ์ด๊ฑธ ํ˜ผ์ž์„œ ์ƒ๊ฐํ•ด๋‚ธ ์‚ฌ๋žŒ๋“ค์€ ์ •๋ง ๋Œ€๋‹จํ•œ๋‹ค........

๋ฐ˜์‘ํ˜•