Pku2992 (approx., prime factor decomposition)

Source: Internet
Author: User

Http: // 162.105.81.212/judgeonline/problem? Id = 2992

 

Question: calculate the number of comments C [N] [K. (0 <= k <= n <= 431)

Idea: the approximate number of a number num is CNT, And the num prime factor is decomposed to obtain num = p1 ^ A1 * P2 ^ A2 * P3 ^ A3 *...... * PN ^.

Then the number of approx. CNT = (A1 + 1) * (A2 + 1) * (A3 + 1 )*...... * (An + 1 ).

C [N] [k] = n! /(N-k )! * K !).

First, calculate the prime number table from 1 to 431. It is easy to time out without preprocessing.

1. Number of approx. Theorem: Let's divide the standard prime factor of N into n = p1 ^ A1 * P2 ^ A2 *... * PM ^ am,
Then the number of factors of N = (A1 + 1) * (A2 + 1) *... * (Am + 1 ).
2. n! The prime factor of = (n-1 )! Prime Factor + N prime factor
3. prime factor decomposition of C (n, k) = n! Prime factor-(n-k )! Prime factor-k! Prime Factor

# Include <iostream> <br/> using namespace STD; <br/> const int maxn = 432; <br/> int res [maxn] [maxn]; // n! <Br/> bool s [maxn]; <br/> int sumprime, prime [maxn]; <br/>/* int P [83] = {2, 3, 5, 7, 11, 13, 17,19, 23,29, 31,37, 41,43, 47,53, 59,61, 67,71, 83,89, 97, <br/> 101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197, <br/> 199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313, <br/> 317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431}; <Br/> name the table 250 ms */<br/> void prime () // evaluate the prime number 172 Ms. <br/>{< br/> int I, K, T; <br/> for (I = 2; I <= 435; I + = 2) {s [I] = 0; s [I-1] = 1 ;}< br/> S [1] = 0; s [2] = 1; <br/> for (I = 3; I <= 30; I + = 2) <br/> {<br/> If (s [I]) <br/> {<br/> K = 2 * I; t = I + k; <br/> while (T <= 435) {s [T] = 0; T = T + k ;}< br/>}< br/> K = 0; prime [0] = 2; <br/> for (I = 3; I <= 435; I + = 2) <br/> {<br/> If (s [I] = 1) {k ++; prime [k] = I ;}< br/>}< br/> sumprime = K; <Br/> // for (I = 0; I <sumprime; I ++) <br/> // printf ("% d", prime [I]); <br/>}< br/> void fun () // integer decomposition n! = P1 ^ T1 *... * PK ^ TK evaluate n! Prime factor decomposition of <br/>{< br/> int I, j, temp; <br/> for (I = 2; I <= 431; I ++) <br/> {<br/> // For (j = 0; j <= I; j ++) <br/> // res [I] [J] = res [I-1] [J]; <br/> temp = I; <br/> for (j = 0; j <sumprime; j ++) <br/>{< br/> while (temp> 1 & TEMP % prime [J] = 0) <br/> {<br/> res [I] [J] ++; // Number of prime factors + +; <br/> temp/= prime [J]; <br/>}< br/> for (I = 3; I <= 431; I ++) <br/> for (j = 0; j <sumprime; j ++) <br/> res [I] [J] + = res [I-1] [J]; <br/>}< br /> Int main () <br/>{< br/> int K, N, I; <br/>__ int64 ans; <br/> prime (); <br/> fun (); <br/> while (scanf ("% d", & N, & K )! = EOF) <br/>{< br/> ans = 1; <br/> for (I = 0; I <sumprime; I ++) // number of factors of N = (A1 + 1) * (A2 + 1 )*... * (Am + 1 ). <br/> ans * = (1 + (RES [N] [I]-res [k] [I]-res [n-k] [I]); <br/> printf ("% i64d/N", ANS); <br/>}< br/> return 0; <br/>}

 

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.