/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 227ms 11.973 MiB
#2 Accepted 243ms 12.27 MiB
#3 Accepted 245ms 12.254 MiB
#4 Accepted 246ms 12.301 MiB
#5 Accepted 247ms 12.375 MiB
#6 Accepted 249ms 12.324 MiB

Code

// Author : Kamonasish Roy (Bullet)
// Time : 2025-03-02 14:02:10

#include<bits/stdc++.h>
using namespace std;
const long long M=1e6+10,MOD=1e9+7;
typedef long long ll;
int p[M];
int prefix[M];
int fre[M];
int limit=1e6;
int divisor(int x,int y){
	vector<int>prime_div;
	while(x>1){
		int cur=p[x];
		while(x>1 && x%cur==0){
			fre[cur]++;
			if(fre[cur]==1)prime_div.push_back(cur);
			x/=cur;
		}
	}
	while(y>1){
		int cur=p[y];
		while(y>1 && y%cur==0){
			fre[cur]++;
			if(fre[cur]==1)prime_div.push_back(cur);
			y/=cur;
		}
	}
	int res=1;
	for(auto it:prime_div){
		res*=(fre[it]+1);
		fre[it]=0;
	}
	return res;
}
void precal(){
	prefix[1]=1;
	prefix[2]=2;
	for(int i=3;i<=limit;i++){
		int x=i,y=i+1;
		if(x % 2==0)x/=2;
		else y/=2;
		prefix[i]=max(divisor(x,y),prefix[i-1]);
	
	}
}
void prime(){
	for(int i=1;i<M;i++)p[i]=i;
	for(int i=2;i<M;i+=2)p[i]=2;
	for(int i=3;i*i<M;i+=2){
		if(p[i]==i){
			for(int j=i*i;j<M;j+=i){
				if(p[j]==j)p[j]=i;
			}
		}
	}
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    prime();
    precal();
    while(t--){
        int n;
        cin>>n;
        cout<<prefix[n]<<"\n";
    	}
    	
    	   
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-03-15 10:15:15
Judged At
2025-03-15 10:15:15
Judged By
Score
100
Total Time
249ms
Peak Memory
12.375 MiB