UVA 160-factors and Factorials

Source: Internet
Author: User

Factors and Factorials

The factorial of a number n (written n!) is defined as the product of the the integers from 1 to n . It is often defined recursively as follows:

Factorials Grow Very rapidly--5! = 120, 10! = 3,628,800. One specifying such large numbers is by specifying the number of times each prime number occurs in it, thus 825 cou LD be specified as (0 1 2 0 1) meaning no twos, 1 three, 2 fives, no Sevens and 1 eleven.

Write a program that would read in a number N () and write out its factorial in terms of the numbers of the prim Es it contains.

Input

Input would consist of a series of lines, each line containing a single integer N. The file would be terminated to a line consisting of a single 0.

Output

Output would consist of a series of blocks of lines, one block for each line of the input. Each block would start with the number N, right justified in a field of width 3, and the characters '!', Space, an d '='. This'll be followed by a list of the number of times each prime number occurs in N!.

These should be right justified in fields of width 3 and each line (except the last of a block, which could be shorter) Shou LD contain fifteen numbers. Any lines after the first should is indented. Follow the layout of the example shown below exactly.

Sample Input

5530

Sample Output

  5! =  3  1  1 53! =  8  4  4  3  2  2  1  1  1  1  1  1        1
#include <cstdio> #include <cstring>using namespace Std;bool isprime (int a) {int i;for (i = 2; i*i <= a;i++) I F (a%i = = 0) return False;return true;} int prime[100], count[100];int main () {int N;int i,num;for (i = 2, num = 0; I <= 100;i++) if (IsPrime (i)) {prime[num++] = i;}  while (scanf ("%d", &n) = = 1 && N) {memset (count,0,sizeof (count)); int maxn = 0;for (i = 2; I <= n; i++) {int m = I;int J;for (j = 0; j < Num; J + +) {while (m%prime[j] = = 0) {m = m/prime[j];count[j]++;if (J>MAXN) MAXN = j;}}} printf ("%3d! = ", n); for (i = 0; I <= maxn; i++) {if (i = =) printf (" \ n      "); printf ("%3d ", Count[i]);} printf ("\ n");} return 0;}

This problem should pay particular attention to the output format.

UVA 160-factors and Factorials

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.