Decomposition factorization Onge teacher C Language Programming Cap 5th Chapter programming problem

Source: Internet
Author: User

Topic content:

Each non-prime (composite) can be written as a number of primes (also known as prime numbers) in the form of multiplication, and these primes are called the composite's mass factor. For example, 6 can be decomposed into 2x3, and 24 can be decomposed into 2x2x2x3.

Now, your program reads an integer in a [2,100000] range, then outputs its mass factorization, and when it reads a prime number, it outputs itself.

Input format:

An integer that is within [2,100000].

Output format:

Shaped like:

N=axbxcxd

Or

N=n

There are no spaces between all the symbols, and x is the lowercase letter x.

Input Sample:

18

Sample output:

18=2x3x3

time limit: 500ms memory limit: 32000kb
#include <stdio.h>//to decompose a positive integer factorizationintMain () {intI,n; scanf ("%d",&N); printf ("%d=", N);  for(i=2; i<=n;i++)    {         while(n!=i)//if i=n, then factorization is n itself.        {            if(n%i==0)//If I is a mass factor, the value of I is printed out and the new value is assigned to n by the quotient{printf ("%DX", i); N=n/i; }            Else  Break;//if not divisible by I, the next i}} printf ("%d\n", n);//here is the last quality factor of the print, which is equal to I    return 0;}

Decomposition factorization Onge teacher C Language Programming Cap 5th Chapter programming problem

Related Article

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.