/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 387ms 8.043 MiB
#2 Accepted 383ms 8.438 MiB
#3 Accepted 359ms 8.465 MiB
#4 Accepted 357ms 8.438 MiB
#5 Accepted 346ms 8.445 MiB
#6 Accepted 343ms 8.52 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 limit=1e6;
int divisor(int x,int y){
	map<int,int>mp;
	while(x>1){
		int cur=p[x];
		while(x>1 && x%cur==0){
			mp[cur]++;
			x/=cur;
		}
	}
	while(y>1){
		int cur=p[y];
		while(y>1 && y%cur==0){
			mp[cur]++;
			y/=cur;
		}
	}
	int res=1;
	for(auto it:mp){
		res*=(it.second+1);
	}
	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-13 09:24:59
Judged At
2025-03-13 09:24:59
Judged By
Score
100
Total Time
387ms
Peak Memory
8.52 MiB