515C - Drazil and Factorial - CodeForces Solution


greedy math sortings *1400

Please click on ads to support us..

Python Code:

x = int(input())
n = input()

factorial = {
    2:[2],
    3:[3],
    4:[3,2,2],
    5:[5],
    6:[3,5],
    7:[7],
    8:[7,2,2,2],
    9:[7,3,3,2]
}

res = []
for i in n:
    num = int(i)
    if num != 1 and num != 0:
        res += factorial[num]

res = sorted(res,reverse = True)
s = ""
for i in res:
    s+=str(i)

print(int(s))
 		 		   	    	  	 	   		   			

C++ Code:

/* ____                       _  __                     _       _       _       
  |  _ \ _ __ ___ _ __ ___   | |/ /__ _ _ __ ___   __ _| |     | | __ _(_)_ __  
  | |_) | '__/ _ \ '_ ` _ \  | ' // _` | '_ ` _ \ / _` | |  _  | |/ _` | | '_ \ 
  |  __/| | |  __/ | | | | | | . \ (_| | | | | | | (_| | | | |_| | (_| | | | | |
  |_|   |_|  \___|_| |_| |_| |_|\_\__,_|_| |_| |_|\__,_|_|  \___/ \__,_|_|_| |_|
*/                                                                            

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;

#define hell    1000000007
#define PI      3.141592653589793238462
#define INF     1e18
#define vi      vector<ll>
#define pb      push_back
#define ppb     pop_back
#define mii     map<ll,ll>
#define pii     pair<ll,ll>
#define mp      make_pair
#define ff      first
#define ss      second
#define all(x)  (x).begin(), (x).end()

/*____________________________________________________________________________________________________________________________________________________________________________________________________*/
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
/*____________________________________________________________________________________________________________________________________________________________________________________________________*/


void solve()
{
    ll n;
    cin>>n;
    ll a;
    cin>>a;
    mii ma;
    while(a!=0){
        ll x=a%10;
        a/=10;
        if(x==0 || x==1){
            continue;
        }
        else if(x==2 || x==3 || x==5 || x==7){
            ma[x]++;
        }
        else if(x==9){
            ma[7]++;
            ma[3]+=2;
            ma[2]++;
        }
        else if(x==8){
            ma[7]++;
            ma[2]+=3;
        }
        else if(x==6){
            ma[5]++;
            ma[3]++;
        }
        else if(x==4){
            ma[3]++;
            ma[2]+=2;
        }
    }

    if(ma[7]!=0){
        for(ll i=0;i<ma[7];i++){
            cout<<'7';
        }
    }
    if(ma[5]!=0){
        for(ll i=0;i<ma[5];i++){
            cout<<'5';
        }
    }
    if(ma[3]!=0){
        for(ll i=0;i<ma[3];i++){
            cout<<'3';
        }
    }
    if(ma[2]!=0){
        for(ll i=0;i<ma[2];i++){
            cout<<'2';
        }
    }
    cout<<endl;
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(ll i=0;i<t;i++){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1665D - GCD Guess
29A - Spit Problem
1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros