티스토리 뷰


title: "팩토리얼 0의 개수(1676)"
category: 백준[Class-3]
tags: [C++, JavaScript, 백준]
date: "2021-04-06"


문제 링크

팩토리얼 0의 개수(1676)

C++

#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

// 문제 풀이 함수
void solution(){
    int n;
    cin >> n;

    int count=0;
    while(n>0){
        n /= 5;
        count += n;
    }
    cout<<count;
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, "r"))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    if(exists("stdin")){
        freopen("stdin", "r", stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}

JavsScript

const fs = require("fs");
const input = fs.readFileSync("dev/stdin").toString().trim().split("\n");

// 문제 풀이
let n = +input[0];

// 소인수 5의 개수
let cnt = 0;
while (n > 0) {
  n = parseInt(n / 5);
  cnt += n;
}
console.log(cnt);
728x90
반응형

'Baekjoon Solutions > Class-3' 카테고리의 다른 글

[백준] 바이러스(2606)  (0) 2021.04.08
[백준] 계단 오르기(2579)  (0) 2021.04.07
[백준] 1로 만들기(1463)  (1) 2021.04.06
[백준] 피보나치 함수(1003)  (0) 2021.04.01
[백준] 비밀번호 찾기(17219)  (0) 2021.04.01
댓글
05-16 09:14
링크