Again Prime? No time.
input: standard input
output: standard output
Time Limit: 1 second
The problem statement is very easy. Given a number n you had to determine the largest power of M., not necessarily prime, that divides n !.
Input
The input file consists of several test cases. The first line in the file was the number of cases to handle. The following lines is the cases each of the which contains the integers m (1<m<5000) and N (0<n<100 ). The integers is separated by a space. There'll be no invalid cases given and there is not more that 's test cases.
Output
For each case in the input, print the case number and result in separate lines. The result is either an integer if mdivides n! or a line "impossible to divide" (without the Qu otes). Check the sample input and output format.
Sample Input
2
2 10
2 100
Sample Output
Case 1:
8
Case 2:
97
Test instructions: give you m,n to ask for the biggest k make is n. of factors;
Idea: the M-quality factor is decomposed into, set p as the largest prime in pi, and then the number of p in the n! is a B, that is, the answer (for I, to find the corresponding B, the smallest)
Code:
<pre name= "code" class= "CPP" > #include <iostream> #include <stdio.h> #include <string.h> #
include<stdlib.h> #include <vector> #include <stdlib.h> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <set> #define INF 0x3f3f3f3f #define EPS 1E-5 #define MAX (a) (a) > (b)? (a):(b) #define MIN (a) (a) < (b)?
(a):(B) using namespace Std;
int sum (int n,int p) {int x=p,ans=0;
while (n/p!=0) {ans+=n/p;
P*=x;
} return ans;
} int main () {int t,n,m,i,j;
scanf ("%d", &t);
{for (i=1;i<=t;i++) {scanf ("%d%d", &m,&n);
printf ("Case%d:\n", i);
int ans=inf,pnum;
for (j=2;m>1;j++) {pnum=0;
while (m%j==0) {pnum++;
M/=j;
} if (Pnum) {int tt=sum (n,j)/pnum;
if (ANS>TT) Ans=tt;
}} if (ans) printf ("%d\n", ans);
else printf ("impossible to divide\n");
}} return 0; }