HDU 1695 GCD (rejection principle + prime factor decomposition)
Preprocessing is performed first to break down the prime factor for each number.
Then, if gcd (x, y) = z, then gcd (x/z, y/z) = 1, because it is definitely not a multiple of z, therefore, if it is not a multiple of z, we can directly remove it. so we only need to divide B and d by k, and then convert it into the logarithm of the mutual quality in the two ranges. In this case, we can enumerate 1 ~ B. Then use the exclusion principle to find 1 ~ D. To avoid duplication, you only need to limit the size relationship. For details, see the code.
The Code is as follows:
#include
#include
#include
#include
#include #include
#include
#include
#include
using namespace std;#define LL __int64const int mod=1e9+7;const int INF=0x3f3f3f3f;LL ans;LL a, b, c, d;vector
vec[110000];void dfs(LL i, int cur, int cnt, LL tmp){ tmp*=(LL)vec[i][cur]; if(cnt&1) { ans+=(LL)min(d,i)/tmp; } else { ans-=(LL)min(d,i)/tmp; } for(int j=cur+1; j
1) vec[i].push_back(x); }}int main(){ int t, i, j, num=0; LL sum, k; init(); scanf("%d",&t); while(t--) { scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&k); num++; if(!k) { printf("Case %d: 0\n",num); continue ; } b/=k; d/=k; if(b