/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 2ms 496.0 KiB
#3 Accepted 2ms 492.0 KiB
#4 Wrong Answer 17ms 324.0 KiB

Code

//Fahmidur Rahman Nafi 62 [i]
#include <bits/stdc++.h>
using namespace std;

vector<bool>sieve(int num) {
    const int N = num + 1;
    vector<bool> isPrime(N, 1);
    isPrime[0] = isPrime[1] = false;

    for (int i = 2; i < N; ++i) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < N; j += i) {
                isPrime[j] = false;
            }
        }
    }
    return isPrime;
}

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

int main(){
    long long int t;
    cin >> t;
    while (t--){
        long long int n;
        cin >> n;
        
        if (n % 2 == 0){
            cout << n/2 << endl;
        }
        else if (sieve(n)[n]){
            cout << 1 << endl;
        }
        else{
            long long int ans = max_div(n);
            cout << ans << endl;
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1052 Yet Another Array Partition
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 17:24:50
Judged At
2024-11-11 03:32:14
Judged By
Score
10
Total Time
17ms
Peak Memory
496.0 KiB