백준 알고리즘 5692번 : 팩토리얼 진법

Zoo Da·2021년 12월 16일
0

백준 알고리즘

목록 보기
292/337
post-thumbnail

링크

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

sol1)

#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;

int fact(int n){
  if(n == 1) return 1;
  return n *fact(n - 1);
}

int32_t main(){
  fastio;
  string x;
  while(cin >> x){
    if(x == "0") break;
    int ret = 0;
    for(int i = 0; i < x.size(); i++){
      int c = x[i] - '0';
      ret += c*fact(x.size() - i);
    }
    cout << ret << "\n";
  }
}
profile
메모장 겸 블로그

0개의 댓글