1101: [poi2007] zaptime limit: 10 sec memory limit: 162 MB
Submit: 1268 solved: 399
[Submit] [Status] Description
FGD is cracking a password. He needs to answer many similar questions: for the given integers A, B, and D, how many positive integers are X, Y, x <=, Y <= B, and gcd (x, y) = D. As a student of FGD, FGD wants your help.
Input
The first line contains a positive integer N, indicating a total of N groups of queries. (1 <= n <= 50000) in the next n rows, each row represents a query, and each row contains three positive integers A, B, and D. (1 <= d <= A, B <= 50000)
Output
For each query group, a positive integer is output to the output file Zap. Out, indicating the integer logarithm that meets the conditions.
Sample input2
4 5 2
6 4 3
Sample output3
2
Hint
For the first group of queries, the integer pairs that meet the conditions include ). For the second group of queries, the integer pairs that meet the conditions are (6, 3), (3, 3 ).
Source
Question:
Jia zhipeng linear screening.
Based on the following techniques:
N/(n/I) is the largest J with N/J = N/I, that is, from I -- N/(n/I) this section N has the same quotient except them
For example, 100/34 = 2 100/(100/34) = 100/2 = 50 34-50, the N-division operator is 2.
Why? This is because we can break down 100 in this way.
100 = 34*2 + 32 smaller than 34, as the remainder
100 = 2*50 + 0 0 smaller than 2, as the remainder
That is to say, as long as we allocate the remainder of the first division to the coefficient of (N/I), we can keep it as much as possible, N/I remains unchanged, and its coefficient is as large as possible, obviously, the N/I coefficient cannot reach the maximum in the past.
This is exactly N/(n/I)
A bunch of nonsense...
Code:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 50000+100014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 using namespace std;22 inline int read()23 {24 int x=0,f=1;char ch=getchar();25 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}26 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}27 return x*f;28 }29 int p[maxn],mu[maxn],sum[maxn];30 bool check[maxn];31 void get()32 {33 int tot=0;34 mu[1]=1;35 for2(i,2,maxn)36 {37 if(!check[i])p[++tot]=i,mu[i]=-1;38 for1(j,tot)39 {40 int k=p[j]*i;41 if(k>maxn)break;42 check[k]=1;43 if(i%p[j])mu[k]=-mu[i];else {mu[k]=0;break;}44 }45 }46 for1(i,maxn)sum[i]=sum[i-1]+mu[i];47 }48 int main()49 {50 freopen("input.txt","r",stdin);51 freopen("output.txt","w",stdout);52 get();53 int cs=read();54 while(cs--)55 {56 ll n=read(),m=read(),x=read(),ans=0;57 n/=x;m/=x;58 if(n>m)swap(n,m);59 for(int s=1,t;s<=n;s=t+1)60 {61 t=min(n/(n/s),m/(m/s));62 ans+=(n/s)*(m/s)*(sum[t]-sum[s-1]);63 }64 printf("%lld\n",ans); 65 }66 return 0;67 }View code
Bzoj1101: [poi2007] zap