UVA10780 Again Prime? No time.

Source: Internet
Author: User

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.

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.