티스토리 뷰

출처 : https://www.hackerrank.com/challenges/extra-long-factorials/problem


#include <bits/stdc++.h>


using namespace std;


void extraLongFactorials(int n) {

    vector<int> v; v.push_back(1);


    for (int i = 2; i <= n; i++) {

        for (auto j = v.begin();j != v.end();j++) *j *= i;


        for (int k = 0; k < v.size(); k++) {

            if (v[k] < 10) continue;

            if (k == v.size() - 1) v.push_back(0);

            v[k + 1] += v[k] / 10; v[k] %= 10;

        }

    }

    for (auto it = v.rbegin(); it != v.rend(); it++) cout << *it;

}


int main()

{

    int n;

    cin >> n;

    cin.ignore(numeric_limits<streamsize>::max(), '\n');


    extraLongFactorials(n);


    return 0;

}


'알고리즘 > 기타' 카테고리의 다른 글

[HackerRank] Non-Divisible Subset  (0) 2018.09.30
[HackerRank] Forming a Magic Square  (0) 2018.09.30
[HackerRank] Climbing the Leaderboard  (0) 2018.09.28
[HackerRank] Time Conversion  (0) 2018.09.27
[HackerRank] Birthday Cake Candles  (0) 2018.09.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함