Ask for the number of intervals [A, b] and N
Using the principle of the tolerant repulsion
The prime factor of N in the [a, b] interval
Ans = the number of numbers divisible by a number-the number of least common multiple divisible by two number + by three number of ...
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace Std;
const int MAXN = 100010;
typedef __int64 LL;
ll P[MAXN]; int len;
void Get_prime (ll N)
{
len = 0;
for (ll i = 2;i*i <= n;i++)
{
if (n%i = = 0) P[++len] = i;
while (n%i = = 0) n/=i;
}
if (n>1) P[++len] = n;
}
ll DFS (int pos, ll N)
{
ll ans = 0;
for (int i = pos; I <= len; i++)
Ans + = n/p[i]-DFS (i+1, n/p[i]);
return ans;
}
int main ()
{
ll A, b, N;
int T;
int cas = 0;
scanf ("%d", &t);
while (t--)
{
scanf ("%i64d%i64d%i64d", &a, &b, &n);
Get_prime (n);
ll ans = (B-dfs (1, b))-(A-1-DFS (1, A-1));
printf ("Case #%d:", ++cas);
printf ("%i64d\n", ans);
}
return 0;
}
Water Problem of hdu4135co-prime principle