Again Prime? No time.
The problem statement is very easy. Given a number n you had to determine the largest power of M,
Not necessarily primes, 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 <) and N
(0 < N < 10000). The integers is separated by a space. There would be no invalid cases given and
There is not more than that of 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 M divides n! Or a line ' impossible to divide ' (without the quotes). 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 m,n; ask for n! Can divide the number of M
Tip: Calculate its mass factor and then ask for its minimum power
#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;intMain () {intT,c=1; CIN>>T; while(t--) { intm,n,p,ans=1000000, A, B; CIN>>m>>N; for(intI=2; m!=1; i++) { intp=0; while(m%i==0) {m/=i; P++; } if(p) {a=n;///start with nb=0;///Number of occurrences while(a) {b+=a/i; A/=i; } ans=min (ans,b/p); }} cout<<" Case"<<c++<<":"<<Endl; if(ans==0) cout<<"impossible to divide\n"; Elsecout<<ans<<Endl; } return 0;}
UVA10780 Again Prime? No time.