- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long unsigned
- #define N 66
- ll fac[N];
- void pre(){
- fac[0] = 1;
- for(int i = 1; i <N; i++) fac[i] = fac[i-1]*i;
- }
- int main(){
- pre();
- int ts;
- scanf("%d", &ts);
- for(int p = 1;p<= ts; p++){
- ll ans;
- scanf("%llu", &ans);
- vector<int> a;
- for(int i = N-1; i>= 0; i--) {
- if(ans>= fac[i]){
- ans = ans-fac[i];
- a.push_back(i);
- }
- }
- if(ans == 0){
- printf("Case %d: ", p);
- sort(a.begin(), a.end());
- for(int i = 0; i <a.size()-1; i++) printf("%d!+", a[i]);
- printf("%d!\n", a[a.size()-1]);
- }
- else printf("Case %d: impossible\n", p);
- }
- //for(int i = 0; i <N; i++) cout<<fac[i]<<" ";
- return 0;
- }
Saturday, 29 July 2017
1189 - Sum of Factorials
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment