정수론 PS #2004

0ne·2024년 2월 11일

Algorithm

목록 보기
18/22
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FASTIO   cin.tie(0);  cout.tie(0); ios_base::sync_with_stdio(0);

int countFactor(long long n, int factor) {
    int count = 0;
    for (long long div = factor; n / div >= 1; div *= factor) {
        count += n / div;
    }
    return count;
}

int main() {
    FASTIO;

    long long n, m; cin >> n >> m;

    int c5 = countFactor(n, 5) - countFactor(n-m, 5) - countFactor(m, 5);
    int c2 = countFactor(n, 2) - countFactor(n-m, 2) - countFactor(m, 2);

    cout << min(c2, c5) << '\n';

}
profile
@Hanyang univ(seoul). CSE

0개의 댓글