2 2 3 3 5
1 1
统计f[i]出现次数即可
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXN (1000000+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} int P[MAXN],siz=0,b[MAXN]={0}; int gcd(int a,int b){if (b) return gcd(b,a%b);return a;} void make_prime(int n) { Fork(i,2,n) { if (!b[i]) { P[++siz]=i; } For(j,siz) { if (P[j]*i>n) break; b[P[j]*i]=b[i]; if (gcd(P[j],i)==1) b[P[j]*i]++; if (i%P[j]==0) break; } } } int t[8],cnt[MAXN][8]={0}; const int n=1000000,mm=7; int main() { // freopen("B.in","r",stdin); make_prime(n); For(i,n) { For(j,7) cnt[i][j]=cnt[i-1][j]+(bool)(b[i]+1==j); } // For(i,30) cout<<i<<' '<<b[i]+1<<endl; int T;cin>>T; while(T--) { int l,r; scanf("%d%d",&l,&r); For(i,7) t[i]=cnt[r][i]-cnt[l-1][i]; int ans=0; For(i,7) For(j,7) { if (t[i]&&t[j]&&((i!=j)||(t[i]>1))) ans=max(ans,gcd(i,j)); } printf("%d\n",ans); } return 0; }