Evaluate the number of prime factors of a number factorial

Source: Internet
Author: User

 

Package namespace; import Java. io. *; import Java. util. *; public class study {// evaluate the prime number public static arraylist <integer> fun (int n) {int A [] = new int [n + 1]; arraylist <integer> List = new arraylist <integer> (); arrays. fill (A, 0); // initialize the array data to 0for (INT I = 2; I <= math. SQRT (double) n); I ++) {for (Int J = I + I; j <= N; j = J + I) {A [J] = 1 ;}}for (INT I = 2; I <= N; I ++) if (a [I] = 0) list. add (I); return list;} public static void main (string ARGs []) {Array List <integer> prime = fun (100); int row, number; partition CIN = new partition (system. in); ROW = cin. nextint (); int count [] = new int [100]; int Max; while (row! = 0) {number = cin. nextint (); arrays. fill (count, 0); max = 0; For (INT I = 2; I <= number; I ++) {int M = I; for (Int J = 0; j <Prime. size (); j ++) {While (M % prime. get (j) = 0) {count [J] ++; M = m/Prime. get (j); If (j> MAX) max = J ;}}for (INT I = 0; I <= max; I ++) system. out. print (count [I] + "") ;}}/** conclusion: Some Questions mean that you should take a factorial of a number, such as 5! = 1*2*3*4*5 find the number of each prime factor of these numbers * 1. first, find all the prime numbers within the given number and put it in an array prime * 2. the following figure shows the input data from two cycles. For each number, you use this number to remove each number in the prime array. If the first number can be divided, then you use an array to record * Add 1 to the original total number, and use this to record the final result * 3. at the same time, a variable is used to record the maximum number of prime numbers that can be divided into all possible values. Otherwise, during the final output, the subsequent large prime numbers may not be exhausted once, the result will be a lot of 0*2011/10/21 *****/

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.