Http://acm.fzu.edu.cn/problem.php? PID = 1564 C (n, k) and prime p

Source: Internet
Author: User

/* <Br/> C (n, k) and prime p <br/> formula: <br/> calculate the number of prime factor p in C (n, k: <br/> 1. convert n to P, and record the sum of each bit of N to S1. <br/> 2. perform the same processing on n-k and K to obtain the number of prime factor p in C (n, k) for S2 and S3 <br/>: <br/> (s2 + S3-S1)/(P-1) <br/> */<br/> # include <iostream> <br/> # include <cstdio> <br/> # include <cstring> <br/> # include <bitset> <br/> # include <cmath> <br/> using namespace STD; <br/> const int n= 1000005; <br/> int prime [N]; <br/> bitset <n> hash; <br/> // bool hash [N]; <br/> in T XI; <br/> void prime () {<br/> // hash. reset (); <br/> // memset (hash, false, sizeof (hash); <br/> int temp = (INT) SQRT (N * 1.0 ); <br/> for (INT I = 2; I <= temp; I ++) <br/> If (! Hash [I]) <br/> for (Int J = I + I; j <n; j + = I) <br/> hash [J] = 1; <br/> xi = 0; <br/> for (INT I = 2; I <n; I ++) <br/> If (! Hash [I]) <br/> prime [XI ++] = I; <br/> // printf ("% d", xi ); <br/>}< br/> void fun (int n, int PP, Int & S) {<br/> S = 0; <br/> while (N) {<br/> S + = n % pp; <br/> N/= pp; <br/>}< br/> int main () {<br/> int t; <br/> prime (); <br/> scanf ("% d", & T); <br/> while (t --) {<br/> int n, m, p; <br/> scanf ("% d", & N, & M, & P ); <br/> int nn = N; <br/> int Mm = m; <br/> int pp = P; <br/> bool flag = false; <br/> int S1, S2, S3; <br/> int sum; <br/> for (INT I = 0; I <Xi & prime [I] <= P; I ++) {<br/> If (P % prime [I] = 0) {<br/> sum = 1; <br/> P/= prime [I]; <br/> while (P % prime [I] = 0) {<br/> sum ++; <br/> P/= prime [I]; <br/>}< br/> fun (n, prime [I], S1 ); <br/> fun (n-M, prime [I], S2); <br/> fun (M, prime [I], S3 ); <br/> If (s2 + S3-S1)/(prime [I]-1) <sum) {<br/> flag = true; <br/> break; <br/>}< br/ >}< Br/> If (P! = 1 &&! Flag) {<br/> sum = 1; <br/> fun (N, P, S1); <br/> fun (n-M, P, S2 ); <br/> fun (M, P, S3); <br/> If (s2 + S3-S1)/(p-1) <sum) {<br/> flag = true; <br/>}< br/> If (FLAG) <br/> puts ("no "); <br/> else <br/> puts ("yes"); <br/>}< 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.