Does fzu 1564 combination contain a factor?

Source: Internet
Author: User

For the Factor M in this question, you only need to convert it into the product form of the prime factor. Then, you only need to determine whether the number of each prime factor P in the combination is greater than or equal to the number in the factor M, if yes, the output is yes. If one is not, the output is no. How to determine the number of prime factors in the number of combinations is as follows:

// Obtain the number of prime factor p in 1*2 * · N
Int getnum (int n, int p ){
Int res;
Res = 0;
While (n ){
Res + = N/P;
N/= P;
}
Return res;
}

The Code is as follows:

# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Define Nmax 46345
Int flag [Nmax], prime [Nmax], pfactor [Nmax], cpfactor [Nmax];
Int Plen, cplen;
// Input the prime number table
Void mkprime (){
Int I, J;
Memset (flag,-1, sizeof (FLAG ));
For (I = 2, Plen = 0; I <Nmax; I ++ ){
If (flag [I]) {
Prime [Plen ++] = I;
}
For (j = 0; (j <Plen) & (I * prime [J] <Nmax); j ++ ){
Flag [I * prime [J] = 0;
If (I % prime [J] = 0 ){
Break;
}
}
}
}
// Convert K into the form of the product of the prime factor
Void findpfactor (int K ){
Int I, Te, CNT;
Te = (INT) SQRT (K * 1.0 );
For (I = 0, cplen = 0; (I <Plen) & (prime [I] <= tE); I ++ ){
If (K % prime [I] = 0 ){
CNT = 0;
While (K % prime [I] = 0 ){
CNT ++;
K/= prime [I];
}
Pfactor [cplen] = prime [I];
Cpfactor [cplen ++] = CNT;
}
}
If (k> 1 ){
Pfactor [cplen] = K;
Cpfactor [cplen ++] = 1;
}
}
// Obtain the number of prime factor p in 1*2 * · N
Int getnum (int n, int p ){
Int res;
Res = 0;
While (n ){
Res + = N/P;
N/= P;
}
Return res;
}
Void solve (int n, int m ){
Int I, temp;
For (I = 0; I <cplen; I ++ ){
Temp = getnum (n, pfactor [I])-getnum (M, pfactor [I])
-Getnum (n-M, pfactor [I]);
If (temp <cpfactor [I]) {
Puts ("no ");
Return;
}
}
Puts ("yes ");
}
Int main (){
# Ifndef online_judge
Freopen ("data. In", "r", stdin );
# Endif
Int t, n, m, K;
Mkprime ();
Scanf ("% d", & T );
While (t --){
Scanf ("% d", & N, & M, & K );
Findpfactor (k );
Solve (n, m );
}
Return 0;
}

 

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.