Back Junアルゴリズム5692号:工場陣法


リンク


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";
  }
}