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 ;}