Friday, 20 February 2015

Codeforces Round #292 (Div. 1) Drazil and Factorial

Problem: Drazil and Factorial

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / hackerrank / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100010


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int tc,kk=1, n, fact[12];
    cin>>n;
    fact[0]=fact[1]=1;
    for(int i=2; i<10; i++)
        fact[i]=fact[i-1]*i;
   
    string s;
    cin>>s;
    int num=1;
    vector<int>v;
    for(int i=0; i<n; i++)
    {
        num=(fact[ s[i]-'0' ] );
        
        while(num%7==0)
        {
            num/=fact[7];
            v.push_back(7);
        }
        while(num%5==0)
        {
            num/=fact[5];
            v.push_back(5);
        }
        while(num%3==0)
        {
            num/=fact[3];        
            v.push_back(3);
        }
        while(num%2==0)
        {
            num/=fact[2];           
            v.push_back(2);
        }
    }

    sort(v.begin(), v.end());
    for(int i=v.size()-1;i>=0;i--)
        cout<<v[i];
    return 0;
}

No comments:

Post a Comment