explanation See factorial factorization (ii)
Factorial factorization (a) time limit: the Ms | Memory Limit:65535 KB Difficulty:2
-
-
Describe
-
Given a two-digit m,n, where M is a prime number.
The factorial of N (0<=n<=10000) is decomposed factorization to find out how many m.
-
-
Input
-
The
-
first line is an integer s (0<s<=100) that represents the number of groups of test data
The following S-line, each line has two integer n,m.
-
-
Output
-
-
the number of output m.
-
-
Sample input
-
-
2100 516 2
-
-
Sample output
-
-
2415
-
-
Source
-
-
Network
-
-
Uploaded by
-
-
Miao-dong building
#include <stdio.h>//is not optimized, int main () {int n,m,s,sum;int i,k;scanf ("%d", &s) with traversal, while (s--) {sum=0;scanf ("%d% D ", &n,&m); for (i=1;i<=n;i++) {k=i;while (k%m==0) {k/=m;sum++;}} printf ("%d\n", sum);} return 0;}
#include <stdio.h>//optimized int main () {int n,m,s;int sum;scanf ("%d", &s), while (s--) {sum=0;scanf ("%d%d", &n , &m); while (n) {sum+=n/m;//because n,m are integers, so in n<m, N/m=0, Plus is Barker, and the last operation is definitely 0 n/=m;} printf ("%d\n", sum);} return 0;}
Nyoj 56 factorial factorization (a) "Math problem"