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.
Ideas:
N! The result is very large. Set n first! Is not feasible, according to n! = 1*2*3 *... * n * (n-1)
Interpret each number in the factorial in sequence, and determine whether it contains a prime number M and how many <=> while (I % key = 0) & I/key)
#include <stdio.h>#include <stdlib.h>int count_Prime(int n,int key){int i; int t=key; int temp; int count=0; for(i=1;i<=n;i++) {temp=i;while((temp/t)&&(temp%t==0)) {count++; temp=temp/t; } } return count;}int main(){int Cases; int value; int key; scanf("%d",&Cases); while(Cases--) {scanf("%d %d",&value,&key); printf("%d\n",count_Prime(value,key)); }return 0;}
[Brush question note 56] factorial decomposition