1435-digit factorial

Source: Internet
Author: User

1435-digit factorial base time limit: 1 second space limit: 131072 KB

X is a positive integer of n-digit number(X=a 0a1an−< Span id= "mathjax-span-27" class= "mn" >1)

Now defineF(X)=∏i=0 n −1 ( Ai!) , such as f (135) =1!*3!*5!=720.

We are given an n-digit integer x (at least one digit greater than 1,x may have a leading 0),

And then we go find a positive integer (s) that meets the following criteria:

1. This number is as large as possible,

2. This number cannot contain numbers 0 or 1.

3.F (s) =f (x)

Input
Each test data is entered in a total of 2 rows. The first line gives an n, which indicates the number of digits in X. (1<=n<=15) The second line gives a positive integer x of n digits (at least one number in X is greater than 1)
Output
A total of one row that represents the maximum value that meets the above criteria.
Input example
41234
Output example
33222
idea: Find the law of composite;
1#include <stdio.h>2#include <algorithm>3#include <string.h>4#include <math.h>5#include <stdlib.h>6#include <queue>7#include <iostream>8 using namespacestd;9 Charstr[ -];Ten BOOLprime[ -]; One intans[ -]; A intt[ -]; - intak[10000]; - intMainvoid) the { -     intN; -     inti,j;prime[0] =true; -      for(i =2; I < -; i++) +     { -         if(!Prime[i]) +         { A              for(j = i; (I*J) < -; J + +) at             { -PRIME[I*J] =true; -             } -         } -}prime[1]=true; -scanf"%d",&n); inscanf"%s", str); -      for(i =0; I < n; i++) to     { +T[i] = str[i]-'0'; -     } the     intUU =0;//printf ("%d\n", Ak[0]); *      for(i =0; I < n; i++) $     {Panax Notoginseng         if(!Prime[t[i]]) -         { theak[uu++] =T[i]; +         } A         Else if(T[i] = =4) the         { +ak[uu++] =2; -ak[uu++] =2; $ak[uu++] =3; $         } -         Else if(T[i] = =6) -         { theak[uu++] =3; -ak[uu++] =5;Wuyi         } the         Else if(T[i] = =8) -         { Wuak[uu++] =2; -ak[uu++] =2; Aboutak[uu++] =2; $ak[uu++] =7; -         } -         Else if(T[i] = =9) -         { Aak[uu++] =3; +ak[uu++] =3; theak[uu++] =2; -ak[uu++] =7; $         } the}//printf ("%d\n", Ak[0]); theSort (ak,ak+UU); the      for(i = uu-1; I >=0; i--) the     { -printf"%d", Ak[i]); in     } theprintf"\ n"); the     return 0; About}

1435-digit factorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.