/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 13ms 584.0 KiB
#2 Accepted 13ms 540.0 KiB
#3 Accepted 13ms 676.0 KiB
#4 Accepted 15ms 672.0 KiB
#5 Runtime Error 13ms 684.0 KiB
#6 Runtime Error 13ms 680.0 KiB
#7 Runtime Error 13ms 684.0 KiB
#8 Runtime Error 12ms 772.0 KiB

Code

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

const int MAX = 1e6 + 5;
vector<bool> isPrime(MAX, true);

void sieve(){
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i * i < MAX; ++i){
        if (isPrime[i]) {
            for (int j = i * i; j < MAX; j += i){
                isPrime[j] = false;
            }
        }
    }
}

int max_div(int num){
    long long int highest = 1;
    for (int i = num / 2; i >= 1; i--){
        if (num % i == 0){
            highest = i;
            break;
        }
    }
    return highest;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    sieve();

    int t;
    cin >> t;
    while (t--) {
        long long int n;
        cin >> n;

        if (n % 2 == 0){
            cout << n / 2 << endl;
        }
        else if (isPrime[n]){
            cout << 1 << endl;
        } 
        else {
            cout << max_div(n) << endl;
        }
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1052 Yet Another Array Partition
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 16:56:00
Judged At
2024-10-03 13:49:23
Judged By
Score
25
Total Time
15ms
Peak Memory
772.0 KiB