CodeForces 396A number theory combined mathematics

Source: Internet
Author: User

Title: http://codeforces.com/contest/396/problem/A

I haven't done things about number theory for a long time. A preprocessing method for getting prime numbers is wrong with prime factor decomposition, so I am crying,

First, the maximum value of ai is 10 ^ 9, and n is 500. In the worst case, the maximum value of m is 500 10 ^ 9, and m cannot be obtained, the first choice is that each ai must be a factor of m, and then ai can be decomposed to the factorization factor, in this way, all ai is decomposed to obtain the number of all prime factors of m and the number of all prime factors. The question is the number of different sequences of n factors, therefore, only n factors can be selected at a time. These factors are composed of prime factors. In fact, they correspond to the number of differentiation methods that each prime factor assigns to n positions, then the product of all the prime factor divisions is the final answer. As for how to allocate it, it is actually the partition method.

In the partition method, there is a rule that allows free time. This question also allows free time.


Example 1: How many different methods can be used to place 20 balls of the same size in three different boxes? Analysis: The size and shape of the ball in this question are identical, so there is no difference between these balls. The problem is equivalent to dividing the ball into three groups. Several groups of non-elements are allowed, and the partition method is used. resolution: to divide 20 small balls into three groups, two partitions are required, because the box is allowed to be empty and does not comply with the principle of the partition method, then add three balls manually, make sure that each box is allocated at least one ball, which meets the requirements of the partition method (after dividing, remove one ball in each group, that is, to meet the requirements of the question ). Then, the total number of small balls to be divided is 23, and there are 22 blank spaces in the middle of the ball. You need to add 2 partitions to the 22 empty spaces to separate them into 3 parts. A total of C) = 231 different methods. comments: if n identical items (or places) are assigned to m people (or places) and several people (or places) are allowed to be empty, it can be seen that the n items are divided into m groups, and several groups are allowed to be empty. divide n items into m groups, and then we need to divide the n items into M-1 groups, from the n + M-1, we select the one-site positions on the storage board. As there is no difference in the storage board, the storage board is disordered and is a combination problem. Therefore, the storage board has different methods such as Cn + M-1 M-1, place the item in other places. Because the item is the same and there is no difference, there is no order between the items. It is a combination problem. There is only one way to put the item. According to the principle of counting by step, there are a total of methods to sort out Cn + M-1 S-1 × 1 = Cn + M-1

Assuming that there are k prime factor p, the division is C [K + N-1] [N-1], and the accumulation is enough.



Const ll MOD = 1000000007; int n; map <int, int> mp; map <int, int>: iterator it; const int MAXN = 15000; int C [MAXN + 1] [500 + 1]; // m is about x * 10 ^ 4500 at the maximum, so about 2 ^ 15000 void Initial () is required () {// combination of int I, j; for (I = 0; I <= MAXN; I ++) {if (I <= 500) C [0] [I] = 0ll; C [I] [0] = 1ll;} for (I = 1; I <= MAXN; ++ I) {for (j = 1; j <= MAXN & j <= 500; j ++) C [I] [j] = (C [i-1] [j] + C [i-1] [j-1]) % MOD ;}# define N 50009int prime [N]; bool isprime [N] ; Int nprime = 0; void make_prime () {// Obtain the prime number memset (isprime, false, sizeof (isprime) within a certain range; for (int I = 2; I <100005; I ++) if (! Isprime [I]) for (int j = I * 2; j <100005; j + = I) isprime [j] = true; for (int I = 2; I <100005; I ++) if (! Isprime [I]) prime [nprime ++] = I;} void divide (int x) {// factorization int temp = (int) sqrt (x * 1.0 ); for (int I = 0; I <nprime; I ++) {if (prime [I]> temp) break; while (x % prime [I] = 0) {mp [prime [I] ++; x/= prime [I] ;}} if (x! = 1) mp [x] ++;} void init () {mp. clear ();} bool input () {while (scanf ("% d", & n) = 1) {return false;} return true;} void cal () {for (int I = 0; I <n; I ++) {int x; scanf ("% d", & x); divide (x );} int ans = 1; for (it = mp. begin (); it! = Mp. end (); it ++) {int tmp = it-> second; // int xx = C [tmp + n-1] [n-1]; // int yy = C [1] [0]; ans = (ans % MOD * C [tmp + n-1] [n-1] % MOD) % MOD ;} cout <ans <endl;} void output () {} int main () {Initial (); make_prime (); while (true) {init (); if (input () return 0; cal (); output ();} return 0 ;}


CodeForces 396A number theory combined mathematics

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.