/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 398ms 15.684 MiB
#2 Accepted 408ms 16.02 MiB
#3 Accepted 413ms 16.086 MiB
#4 Accepted 412ms 16.098 MiB
#5 Accepted 414ms 16.098 MiB
#6 Accepted 414ms 16.09 MiB

Code

#include<bits/stdc++.h>
using namespace std;

#define int        long long int
#define pb         push_back
#define all(x)     x.begin(),x.end()
#define allr(x)    x.rbegin(),x.rend()
#define ii         pair<int,int>
#define endl       '\n'

const int N = 1e6 + 2;
vector<int> spf(N, 0), ans(N);

void preCal() {
	for(int i = 2 ; i < N ; i++) {
		if(spf[i] == 0) {
			for(int j = i ; j < N ; j += i) {
				if(spf[j] == 0)
					spf[j] = i;
			}
		}
	}
	int best = -1, maxDiv = 0;
	for(int i = 1 ; i < N - 1 ; i++) {
		int p = i;
		map<int, int> m;
		while(p > 1) {
			m[spf[p]]++;
			p /= spf[p];
		}
		p = i + 1;
		while(p > 1) {
			m[spf[p]]++;
			p /= spf[p];
		}
		m[2]--;
		int div = 1;
		for(auto [e, f] : m) {
			div *= (f + 1);
		}
		if(div >= maxDiv) {
			best = i;
			maxDiv = div;
		}
		ans[i] = maxDiv;
	}
}

void pipra(int tc) {
    int n;
    cin >> n;
    cout << ans[n] << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    preCal();
    int t = 1;
    cin >> t;
    for(int i = 1 ; i <= t ; i++)
        pipra(i);
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-09 12:30:52
Judged At
2025-04-09 12:30:52
Judged By
Score
100
Total Time
414ms
Peak Memory
16.098 MiB