Nyist 56 factorial decomposition (1)

Source: Internet
Author: User
Factorial Factorization (I) time limit: 3000 MS | memory limit: 65535 kb difficulty: 2
Description

Given two numbers m, n, where M is a prime number.

Returns the factorial of N (0 <= n <= 10000) to calculate the number of M.

 
Input
The first row is an INTEGER (0 <S <= 100), indicating the number of test data groups.
The next s row has two integers n and M.
Output
Number of output M.
Sample Input
2100 516 2
Sample output
2415






 

 

 

# Include <stdio. h>
Int main ()
{
Int S1, n, m, S, J, I, II;
Scanf ("% d", & S1 );
While (S1 --)
{S = 0;
Scanf ("% d", & N, & M );
For (I = 1; I <= N; I ++)
{II = I;
If (II % m = 0)
{
S ++; II = II/m;

While (II % m = 0)
{
S ++; II = II/m;
}
}
}
Printf ("% d \ n", S );
}
}

 

 


# Include <iostream>
Using namespace STD;
Int main ()
{
Int m, n, k, S, sum;
Cin> S;
While (s --)
{
Sum = 0;
Cin> N> m; // M is a prime number.
While (N)
{
K = N/m;
Sum + = K;
N = K;
}
Cout <sum <Endl;
}
}


// Factorial decomposition. I thought it would be n! The number of M in all factorial values.
// This is not the original meaning.
// The description of the question is incorrect.
// 100/5 = 20 5
// 20/5 = 4 5
// 4/5 = 0 5
// End
// 20 + 4 + 0 = 24

 


**************************************** ***********

8 *************************************** **************************************** ******

 


# Include <stdio. h>
Int main ()
{
Int count, n, m, I, ii, T;

Scanf ("% d", & T );
While (t --)
{
Count = 0;
Scanf ("% d", & N, & M );
For (I = 1; I <= N; I ++)
{II = I;
If (II % m = 0) // check one by one
{
Count ++; // + 1
II = II/m; // whether the new II contains a certain power of m

While (II % m = 0) // a power of m
{Count ++; II = II/m ;}//
}


}
Printf ("% d", count );
}

}

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.