# UVA10780 exponentiation and factorial

Source: Internet
Author: User
Tags cas printf
Test instructions
Enter two integers n,m (1<m<5000,0<n<10000) to find the smallest k so that m^k is the n! factor.

Ideas:
Relatively easy to think, at the beginning of the hands of the WA several times, we directly find M and n! prime factor and number on the line, if S1[a] represents the number of prime factor a n!, S2 is M, then Ans=min (Ans, s1[a]/s2[a]); This should not be explained, well understood.

#include <stdio.h>
#include <string.h>

int pri, pt;
int mark;
int s1, s2;

void Dbpri ()
{
memset (mark, 0, sizeof (Mark));
MARK = 1;
PT = 0;
for (int i = 2; I <= 10000; i + +)
{
if (!mark[i])
{
PRI[++PT] = i;
for (int j = i + i; J <= 10000; j + = i)
MARK[J] = 1;
}
}
}

int main ()
{
Dbpri ();
int T, CAS = 1, I, J, N, M;
scanf ("%d", &t);
while (t--)
{
scanf ("%d%d", &m, &n);
memset (S1, 0, sizeof (S1));
for (i = 1; I <= n; i + +)
{
int now = i;
for (j = 1; PRI[J] <= now && J <= pt; j + +)
{
while (now% pri[j] = = 0)
{
Now/= Pri[j];
S1[PRI[J]] + +;
}
}
}

memset (s2, 0, sizeof (S2));
int mm = m;
for (i = 1; Pri[i] <= mm && i <= pt; i + +)
if (mm% pri[i] = = 0)
{
while (mm% pri[i] = = 0)
{
S2[pri[i]] + +;
MM/= pri[i];
}
}
int Ans = 100000;
for (i = 1; Pri[i] <= m && i <= pt; i + +)
if (m% pri[i] = = 0)
{
if (Ans > S1[pri[i]]/s2[pri[i])
Ans = S1[pri[i]]/s2[pri[i]];
}

printf ("Case%d:\n", CAS + +);
if (Ans = = 0) printf ("Impossible to divide\n");
else printf ("%d\n", Ans);
}
return 0;
}

Related Keywords:

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.