FCDC - Factorial Modulo
You are given 2 integers a, b. Find the number of i for which i! is divisble by a but not b. if i! is divisible by a and b, then you should not count that i.
Input
One line that contains a and b.
Output
Output the result in one line.
Example
Input: 2 3 Output: 1
Constraints
1 ≤ a ≤ b ≤ 107
Explanation
2! is the only factorial which is divisible by 2 and not divisible by 3.
思路:加如x!可以整除a,那么(x+1)!,(x+2)!......都可以整除a,那么找出各自最小的x!然后作差即可。
# include <bits/stdc++.h>
using namespace std;
int get(int a, int b)//计算最小的x,使得X!分解质因数有a个b。
{
int dp[35]={0};
for(int i=1;;++i)
{
dp[i] = i+dp[i/a];
if(dp[i] >= b)
return i*a;
}
}
int cal(int n)
{
int t = 0;
for(int i=2; i<=sqrt(n); ++i)
{
if(n%i==0)
{
int icount = 0;
while(n%i==0)
{
n /= i;
++icount;
}
t = max(t, get(i, icount));//取最大的。
}
}
if(n > 1) t = max(t, n);
return t;
}
int main()
{
int a, b, t1, t2;
scanf("%d%d",&a,&b);
if(b==1) return puts("0");
t1 = cal(a);
t2 = cal(b);
if(a==1) printf("%d\n",t2-1);
else printf("%d\n",max(t2-t1, 0));
return 0;
}