UVA 10780Again Prime? No time. (Simple number theory)

Source: Internet
Author: User

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&GT;TT) Ans=tt;
            }} if (ans) printf ("%d\n", ans);
        else printf ("impossible to divide\n");
}} return 0; }




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.