CCNU exercise for week 5: break down a number into the form of a quality factor multiplied

Source: Internet
Author: User
K-
Number Theory-2

Time Limit:1000 msMemory Limit:32768kb64bit IO Format:% I64d
& % I64u

Submitstatus

Description

Eddy's interest is very extensive, recently he is interested in prime number. eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, So Eddy has
To ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor.

 

Input

The input will contain in a number 1 <x <= 65535 per line representing the number of elements of the set.
 

Output

You have to print a line in the output for each entry with the answer to the previous question.
 

Sample Input

119412
 

Sample Output

112*2*13*181 the number of questions has been clearly explained, and a number is decomposed into the form of a qualitative factor multiplication, well, the maximum number is 65536, which is roughly estimated. In the range of 2*3*5*7*11*13*17, the array should be larger --, so what we need to do is three more things: 1. determine prime number 2. filter prime numbers in this large range. perform a qualitative factorization on this number. Of course, pay attention to the output format of this question--the direct output of prime numbers is very easy to write, this is mainly the form of concatenation. I didn't pay attention to it at the beginning. As a result, each number of factors that can be decomposed by a qualitative factor is eventually added to ORZ. However, after the change, the following code is pasted on the AC, there is a comment in the code.
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace std; int prime [100005]; bool check (int n) {int I; if (n = 2) return true; for (I = 2; I * I <= n; I ++) {if (n % I = 0) return false;} return true;} int main () {int n; int I, j = 0; int a [1005]; for (I = 2; I <= 65536; I ++) // all prime numbers in the brute-force screening range are saved in the array {if (check (I) = true) {prime [j ++] = I ;}while (cin> n) {int k = 0, flag = 0; if (check (n) = true) cout <n <endl; else {while (n> 1) {if (n % prime [flag] = 0) // if this prime number can be divisible, the number is decomposed into {a [k ++] = prime [flag]; n = n/prime [flag];} else flag ++; // otherwise, find the next prime number in the filtered prime number to judge} for (int t = 0; t <k; t ++) {if (t = k-1) printf ("% d \ n", a [t]); // if you get the last direct output, you don't need to use * else printf ("% d *", a [t]); // otherwise, a * number will be added each time. }}return 0 ;}

 

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.